填写特定列的特定文本

问题描述 投票:0回答:1

我是Stackoverflow和VBA领域的新手。实际上,我的代码需要一些帮助。

我创建了一个VBA(宏),似乎我的代码丢失了。

场景:

[如果B3列有答案(“ FLAT”或“ PER”)应适用于与A3列相同的所有列

例如

如果A3直到A500,那么B3直到B500也有答案(“ FLAT”或“ PER”)。

Sub exe()

    Dim number As Integer, result As String

    number = Range(“a1”).Value

    If number <= 1 Then

    result = “Flat”

    Else: result = “Per”

    End If

    Range(“b1”).Value = result

End Sub
excel vba
1个回答
0
投票

您是否正在寻找类似的东西:

Sub exe()

    Dim LastRow As Long, i As Long

    With ThisWorkbook.Worksheets("Sheet1")

        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For i = 1 To LastRow

            If .Range("A" & i).Value = 0.5 Then
                .Range("B" & i).Value = "FLAT"
            ElseIf .Range("A" & i).Value = 2 Then
                .Range("B" & i).Value = "PER"
            End If

        Next i

    End With

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.