获取事件的价值位置

Obtain Position of value for Event

您好,我一直在努力寻找执行此操作的最佳方法,但不幸的是,我采取的步骤并没有给我希望的结果。我想创建一个突出显示单元格的事件,但前提是它位于特定范围内。现在棘手的部分是范围可以根据我创建的按钮显示的信息而改变。例如,我有 A1、A2,按下按钮后,范围可以更改为 A1..A5。例如,我不希望单元格 A6 突出显示,因为此处没有信息或那里的信息无关紧要。这是我到目前为止所做的,但目前在循环内的 INSTR 函数上收到应用程序定义或对象定义错误。我为此活动在 class 中创建了以下内容:

Private Sub m_wb_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim i As Integer
Dim startpos As Integer
Dim Endpos As Integer
For i = 0 To 50
    If (InStr(m_wb.Sheets("sheet1").Cells(i, 5).Value, "multiplier") > 0) Then startpos = i
    If (InStr(m_wb.Sheets("sheet1").Cells(i, 5).Value, "total") > 0) Then Endpos = i
Next i
If Sh.name = "Sheet1" And (Target.Column = 7 Or Target.Column = 2 Or Target.Column = 3) And Not IsEmpty(m_wb.Sheets("sheet1").Cells(3, 1).Value) And Target.Row > startpos - 1 and Target.Row < Endpos Then Target.Interior.Color = vbYellow
End Sub

"The row value cannot be 0 and hence you are getting that error" - @SiddharthRout