我正在尝试在表中插入多行。
我一直在尝试使用.DataBodyRange.Rows(0:100).insert
,但是问题是.DataBodyRange
在表为空(0行)时返回错误。
那么还有其他选择吗?假设我不想在循环中逐行添加。
答案 0 :(得分:0)
我想我已经解决了我的问题。 添加一行后,databodyrange不再返回错误,并且可以在该行之后插入几行。 尽管必须假设只有1行,但我必须检查rows(1:1)是否返回错误。
If .ListRows.Count < rowi + 1 Then
If .ListRows.Count = 0 Then
.ListRows.Add
End If
.DataBodyRange.Rows(.ListRows.Count + 1 & ":" & rowi).Insert Shift:=xlDown
答案 1 :(得分:0)
当.DataBodyRange
为Nothing
时,.InsertRowRange
是什么东西。
所以您可以做类似的事情
If .DataBodyRange Is Nothing Then
.InsertRowRange.Resize(100).Insert
Else
.DataBodyRange.Resize(100).Insert
End If