Vba 尝试选择以变量作为列号的单元格
我试图设置一个代码,使用find函数查找单元格,然后在该列中选择另一个单元格。我将列号存储为一个变量,然后尝试使用该变量移动到同一列中的单元格,但它不起作用 我尝试更改它,使列存储为字符串而不是整数,并尝试改用.Cells方法,但两者都不起作用Vba 尝试选择以变量作为列号的单元格,vba,Vba,我试图设置一个代码,使用find函数查找单元格,然后在该列中选择另一个单元格。我将列号存储为一个变量,然后尝试使用该变量移动到同一列中的单元格,但它不起作用 我尝试更改它,使列存储为字符串而不是整数,并尝试改用.Cells方法,但两者都不起作用 Dim numCol As String Cells.Find(what:="e", After:=ActiveCell, LookIn:=xlFormulas, LookAt _ :=xlPart, SearchOrder:=xlByRows
Dim numCol As String
Cells.Find(what:="e", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=
_
False, SearchFormat:=False).Activate
numCol = ActiveCell.Column
Range(numCol & "4").Select
从最后一行代码中获取1004“对象全局的方法范围失败”错误。以下是查询中的一些修改代码,可能会很有用。您想尝试使用。在下面的示例中,我定义了一个范围,即找到的单元格
fcell
。这里有几个例子说明你可以做些什么
Dim numCol As Long
Dim fcell As Range
'this will find the cell and set it as a variable of fcell
Set fcell = Cells.Find(what:="e", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
'you can select it
fcell.Select
'you can select the whole column
fcell.EntireColumn.Select
'you can select the column number (if one column)
numCol = fcell.Column
'you can return the address
MsgBox "the address is " & fcell.Address
祝你好运。这里有一些查询中修改过的代码,可能会有用。您想尝试使用。在下面的示例中,我定义了一个范围,即找到的单元格
fcell
。这里有几个例子说明你可以做些什么
Dim numCol As Long
Dim fcell As Range
'this will find the cell and set it as a variable of fcell
Set fcell = Cells.Find(what:="e", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
'you can select it
fcell.Select
'you can select the whole column
fcell.EntireColumn.Select
'you can select the column number (if one column)
numCol = fcell.Column
'you can return the address
MsgBox "the address is " & fcell.Address
祝你好运。
将numCol变暗,只要长一点
,然后单元格(4,numCol)
。但是您可能不需要使用激活
或选择
。请参阅。numCol
是一个整数。将其转换为字符串将得到类似于范围(“14”)。选择,则该范围标识符无效。BigBen有解决方案,这只是误用或误解了Range
参数的工作原理。干杯。将numCol设置为长
,然后单元格(4,numCol)
。但是您可能不需要使用激活
或选择
。请参阅。numCol
是一个整数。将其转换为字符串将得到类似于范围(“14”)。选择,则该范围标识符无效。BigBen有解决方案,这只是误用或误解了Range
参数的工作原理。干杯