【问题标题】:Find last row with two conditions on columns在列上查找具有两个条件的最后一行
【发布时间】:2020-03-19 22:13:19
【问题描述】:

我正在寻找符合以下两个条件的 Excel 数据集的最后一行:
Myrow's Column("E") = some_value
Myrow 的 Column("K") 不为空

如果 column("K") 为空,则查找满足上述条件的 previous 行。

只要对应的列(“K”)为空,我想继续循环遍历列(“E”)。

我尝试了以下方法:

With worksheets("myworksheet"):
Set my_first_cell = Range(“E:E”).Find(What:="some_value", lookin:xlValues, 
SearchDirection:=xlPrevious)
Set my_second_cell = my_first_cell.Offset(0,6)
If Not my_second_cell Is Nothing Then:
    myrow=my_second_cell.Row
Do
Set my_first_cell= .FindPrevious(my_first_cell)
Loop While my_second_cell Is Nothing
End If
End With

【问题讨论】:

    标签: excel vba loops find row


    【解决方案1】:

    看看,我用K列最后一行开始

    Sub Button2_Click()
        Dim sh As Worksheet, LstRw As Long
        Dim x
        Dim myRow As String
        Set sh = Worksheets("myworksheet")
    
        With sh
    
            LstRw = .Cells(.Rows.Count, "K").End(xlUp).Row
    
            For x = LstRw To 2 Step -1
    
                If .Cells(x, "K") <> "" And .Cells(x, "E") = "some_value" Then
                    myRow = x
                    Exit For
                End If
    
    
    
            Next
    
        End With
    
        MsgBox myRow
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      相关资源
      最近更新 更多