Option Explicit
Sub FillEmpty()
Dim ws As Worksheet
Dim myRange As Range
Dim lColumn As Long
Dim x As Integer
Set ws = Worksheets("Sheet1")
'Find the last column that contains data
lColumn = ws.Cells.Find(What:="*", _
After:=ws.Cells(1, 1), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
With ws
For x = lColumn To 2 Step -1
If .Cells(1, x) = "AR" Then
.Cells(1, x - 1).Value = "OV"
ElseIf .Cells(1, x) = "DP" Then
.Cells(1, x - 1).Value = "OS"
ElseIf .Cells(1, x).Value <> "" And .Cells(1, x - 1).Value = "" Then
.Cells(1, x - 1).Value = .Cells(1, x).Value
End If
Next x
End With
End Sub
1 回答
通常我们希望你发布你到目前为止所做的事情,但我很好奇我是否能够编码或不编码 . 所以!试试这个 . 如果需要在多行上执行此操作,则可以添加另一个循环并将1更改为变量 . 希望这可以帮助!