VBA – 使用find添加列

我试图添加2列使用查找,我得到一个错误。

.Columns(Rows(1).Find("Eot")).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove 

这是原来的代码:

  .Columns("I:J").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove 

这将在列的左侧插入两列,并find值:

 .Rows(1).Find("Eot").EntireColumn.Resize(, 2).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove 

您错过了Range对象的Column属性(通过.Find方法返回)以返回列索引号并将其提供给.Columns()集合

 .Columns(rows(1).Find("Eot").Column).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove