我正在尝试根据VBA中的列标题动态选择列。这是我正在使用的代码,
Sub trial()
Dim colm As Long
Dim nwb As Workbook, wb As Workbook
Dim nwk As Worksheet, wk As Worksheet, wk1 As Worksheet
co1m = WorksheetFunction.Match("Header", Sheets("Sheet1").Rows(1), 0)
Columns(colm).Select
End Sub
当我尝试调试它时,它在colm中显示5的值,同时在下一行列(colm).select上显示,它在colm的位置显示0。请帮助我解决这个问题。提前致谢
答案 0 :(得分:1)
你那里有拼写错误!您有co1m
和colm
。
使用Option Explicit
会抛出编译错误,说明co1m
没有声明! ;)
Option Explicit
Sub trial()
Dim colm As Long
Dim nwb As Workbook, wb As Workbook
Dim nwk As Worksheet, wk As Worksheet, wk1 As Worksheet
colm = WorksheetFunction.Match("Header", Sheets("Sheet1").Rows(1), 0)
Columns(colm).Select
End Sub