我尝试创建一个宏来查看F列,然后从第一行一直到最后一行更新第一列。
因此,请阅读SBS的F列,然后使用" National"
更新第I列的相应行这是我的代码。
Dim LastRow As String
Dim d As String
LastRow = Range("F" & Rows.Count).End(xlUp).Row
For d = SBS To LastRow
If Not IsEmpty(Range("F" & d).Value) Then
Range("I" & d).Value = "National"
End If
Next d
答案 0 :(得分:0)
以下是快速示例
Option Explicit
Public Sub Example()
Dim Sht As Worksheet
Dim Rng As Range
Set Sht = ThisWorkbook.Sheets("Sheet1")
For Each Rng In Sht.Range("F1", Sht.Range("F9999").End(xlUp))
If Rng.Value = "SBS" Then
Rng.Cells.Offset(0, 3).Value = "National"
End If
Next
End Sub
答案 1 :(得分:0)
在D和if条件的Dim语句中对宏进行了微小的更改。也不需要空状态: -
Sub Macro1()
Dim LastRow As Long
Dim d As Long
LastRow = Range("F" & Rows.Count).End(xlUp).Row
For d = 1 To LastRow
If Range("F" & d).Value = "SBS" Then
Range("I" & d).Value = "National"
End If
Next d
End Sub