Excel VBA“;对象变量或未设置块变量";

Excel VBA“;对象变量或未设置块变量";,excel,vba,Excel,Vba,我有以下代码: Sub CheckDates() bAlarm = False i = 1 Do Until ActiveSheet.Cells(row_header, i).Value = "" If ActiveSheet.Cells(row_header, i).Value = searchText Then col = i Exit Do End If i = i + 1 Loop i = 1 Do Until ActiveSheet

我有以下代码:

Sub CheckDates()

bAlarm = False

i = 1
Do Until ActiveSheet.Cells(row_header, i).Value = ""
    If ActiveSheet.Cells(row_header, i).Value = searchText Then
        col = i
        Exit Do
    End If
i = i + 1
Loop

i = 1
Do Until ActiveSheet.Cells(row_header, i).Value = ""
    If ActiveSheet.Cells(row_header, i).Value = searchNameText Then
        col_name = i
        Exit Do
    End If
i = i + 1
Loop

If col = 0 Then
    MsgBox searchText & " basliklar arasinda bulunamadi"
    Exit Sub
Else
    N = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    For i = row_header + 1 To N
        If isInDateRange(ActiveSheet.Cells(i, col).Value) Then
            With UserForm1.ListBox1
                .AddItem
                .List(.ListCount - 1, 0) = ActiveSheet.Cells(i, col_name).Value
                .List(.ListCount - 1, 1) = ActiveSheet.Cells(i, col).Value
            End With
            bAlarm = True
        End If
    Next i
End If

If bAlarm = True Then
    UserForm1.Show
End If

我在ActiveSheet.Cells(行标题,I).Value=”“行上获取
对象变量或未设置块变量(错误91)
错误。调试时,我可以看到
hprlink.Range
确实有一个值。你知道我做错了什么吗?

除非你的问题中缺少代码,否则我认为问题确实在于:

Do Until ActiveSheet.Cells(row_header, i).Value = ""
据我所知,
row\u header
此时为空,因此可能会解析为:

Do Until ActiveSheet.Cells( 0, 1).Value = ""
没有第0行,因此您得到了错误

在开始循环查找字段之前,在
行标题中输入一个值(可能是
1
-我看不到您的工作表?)

此外,您可能希望签出
WorksheetFunction.Match
,因为它将执行与前两个循环仅使用一行相同的操作

最后,您可能应该停止在子系统中始终引用
ActiveSheet
,或者在开始引用时使用
With
块或
设置对象