我对 VBA 不太熟悉,所以请耐心等待。
在我的工作簿的第 5 表中,我试图找到该值的第一个实例
0.25
在细胞之间
K21:K40
对表格进行排序后。
当我运行下面的代码时,
Public Row_Num As Integer
Sub SortMultipleColumns()
With ActiveSheet.Sort
.SortFields.Add Key:=Range("L1"), Order:=xlAscending
.SortFields.Add Key:=Range("C1"), Order:=xlAscending
.SetRange Range("B21:N40")
.Header = xlYes
.Apply
End With
Dim today As Double
Dim row_today As Long
Value1 = 0.25
row_of_value = ThisWorkbook.Sheets("Sheet5").Range("K21:K40").Find(What:=Value1, LookIn:=xlValues).Row
Debug.Print row_of_value
End Sub
我收到错误
运行时错误“9”:下标超出范围
但是,我尝试了以下代码:
Public Row_Num As Integer
Sub SortMultipleColumns()
With ActiveSheet.Sort
.SortFields.Add Key:=Range("L1"), Order:=xlAscending
.SortFields.Add Key:=Range("C1"), Order:=xlAscending
.SetRange Range("B21:N40")
.Header = xlYes
.Apply
End With
Dim today As Double
Dim row_today As Long
Value1 = 0.25
row_of_value = ActiveSheet.Range("K21:K40").Find(What:=Value1, LookIn:=xlValues).Row
Debug.Print row_of_value
End Sub
我收到错误
运行时错误“91”:未设置对象变量或 With 块变量
我需要有关如何使这些代码正常工作的建议