我试图为特定列的全部内容声明一个范围,但是范围对象有问题。我的代码能够找到所需的列和该列中的数据的最后一行,但是当我尝试使用这些变量设置范围时,出现错误。
columnNamesRow = 1 ' or whichever row your names are in
nameToSearch = "Network Type" ' or whatever name you want to search for
EONTC = 0
lastUsedColumn = ActiveSheet.Columns.Count
For col = 1 To lastUsedColumn
If ActiveSheet.Cells(columnNamesRow, col).Value = nameToSearch Then
EONTC = col
End If
Next col
EOLR = 0
With ActiveSheet
EOLR = .Cells(.Rows.Count, EONTC).End(xlUp).Row
End With
'this next portion of code is in a different subroutine within the same
'module; all variables are public
Dim EORange As Range
Set EORange = Sheets("EO").Range(Cells(1, EONTC), Cells(EOLR, EONTC))
因此,使用断点,我能够确定变量具有正确的值,即EONTC = 23和EOLR = 10000。但是,每当我运行宏时,最后一行代码仍然会引发错误。也许我的语法或range对象的实现有问题,非常感谢您的帮助!