VBA If语句跨越多行

时间:2017-10-26 19:58:03

标签: vba excel-vba excel

我目前有这段代码:

For Each ARange In ws.Range("L1:L28000").Rows
    If ARange(1).Value = "John" Or ARange(1).Value = "Thomson" Or ARange(1).Value = "Mattson" Or ARange(1).Value = "Powers" Or ARange(1).Value = "Hermkens" Or ARange(1).Value = "Licka" Or ARange(1).Value = "Fout" Or ARange(1).Value = "Marrin" Or ARange(1).Value = "Fleming" Or ARange(1).Value = "Waiblinger" Or ARange(1).Value = "Lambertson" Or ARange(1).Value = "Solis" Or ARange(1).Value = "Deot" Or ARange(1).Value = "Large" Or ARange(1).Value = "Gannon" Or ARange(1).Value = "FAUGHNAN" Or ARange(1).Value = "COMPLIANCE" Or ARange(1).Value = "Jacobs" Or ARange(1).Value = "Powers" Or ARange(1).Value = "TSH" Or ARange(1).Value = "WRONG LOCATION CODE" Then
        If DRange Is Nothing Then
            Set DRange = ARange
        Else
            Set DRange = Union(DRange, ARange)
        End If
    End If
Next ARange

然而,第一个if语句是我无法在不滚动的情况下读取的所有行,是否可以将代码分解但仍然可以按预期运行?

2 个答案:

答案 0 :(得分:3)

datetime

答案 1 :(得分:2)

喜欢这个吗?

    <Style TargetType="{x:Type TextBlock}" x:Key="TextBlockStyle">
        <Setter Property="Foreground" Value="WhiteSmoke"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsEnabled, 
                RelativeSource={RelativeSource AncestorType=ComboBox}}" Value="True">
                <Setter Property="Foreground" Value="Black"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding IsEnabled, 
                RelativeSource={RelativeSource AncestorType=DatePicker}}" Value="True">
                <Setter Property="Foreground" Value="Black"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>