我尝试在列之间添加空白列并在其中包含信息,但我很困惑为什么我的代码会从第二列开始添加指数级数量的列。
Dim iCol As Integer
For iCol = lastCol + 2 To 3 Step -1
ThisWorkbook.Worksheets("Sheet4").Columns(iCol).Insert
Next
答案 0 :(得分:2)
尝试,
Dim iCol As long, lCol as long
with ThisWorkbook.Worksheets("Sheet4")
lcol = .cells(1, .columns.count).end(xltoleft).column
For iCol = lcol to 3 Step -1
.Columns(iCol).Insert
Next
end with
第1行必须有.end(xltoleft)到' catch'。