在基于行标题-VBA的特定列之前插入新列
我只是试图根据标题search一个特定的列,并在它之前插入一个新的列(所以在列的左侧)。 现在我的代码search所有列,甚至包含我的search,并在左侧插入一个新的列2列。 例如,我想search标题,说只有Paid to Date
但它甚至插入一个列旁边Commission Paid to Date
等
Sheets(NewSheet).Select Set ColHeaders = Range("A4:CD4").Find("Paid to Date") If ColHeaders Is Nothing Then MsgBox "Paid to Date Column was not found." Exit Sub Else Columns(ColHeaders.Column).Offset(0, -1).Insert End If
在确认解决scheme所花费的时间,这似乎是在评论中回答。
- 删除偏移量,因为它将默认插入到列中
- 阅读这里
Find
的文档,并指定参数LookAt
为xlWhole
( 根据枚举 ,将值设为 1)