-3

我从这个站点获得了以下代码,它选择了 H 列中包含值“1”的所有单元格,它工作得很好,但我希望你能帮助我选择 H 列中包含负值的所有单元格

Sub H()
    Dim TheSheet As Worksheet
    If TypeOf ActiveSheet Is Worksheet Then
        Set TheSheet = ActiveSheet
    Else
        Exit Sub
    End If
    Dim Row As Integer
    Dim CellsToSelect As String
    For Row = 1 To TheSheet.Range("H" & CStr(TheSheet.Rows.Count)).End(xlUp).Row
        If TheSheet.Range("H" & CStr(Row)).Value = 1 Then
            If CellsToSelect <> "" Then CellsToSelect = CellsToSelect & ","
            CellsToSelect = CellsToSelect & "H" & CStr(Row)
        End If
    Next Row
    TheSheet.Range(CellsToSelect).Select
End Sub

感谢如果提前诺埃尔

4

1 回答 1

0

更改此行:If TheSheet.Range("H" & CStr(Row)).Value = 1 Then

对此:If TheSheet.Range("H" & CStr(Row)).Value < 0 Then

为了您的方便,这里是整个子。

 Sub H()
    Dim TheSheet As Worksheet
    If TypeOf ActiveSheet Is Worksheet Then
        Set TheSheet = ActiveSheet
    Else
        Exit Sub
    End If
    Dim Row As Integer
    Dim CellsToSelect As String
    For Row = 1 To TheSheet.Range("H" & CStr(TheSheet.Rows.Count)).End(xlUp).Row
        If TheSheet.Range("H" & CStr(Row)).Value < 0 Then
            If CellsToSelect <> "" Then CellsToSelect = CellsToSelect & ","
            CellsToSelect = CellsToSelect & "H" & CStr(Row)
        End If
    Next Row
    If Len(CellsToSelect) <> 0 Then
        TheSheet.Range(CellsToSelect).Select
    End If
End Sub
于 2012-09-08T02:09:09.180 回答