答案 0 :(得分:5)
试试这个:
Sub Demo()
Dim rng As Range
Dim lastRow As Long
Dim cell as Range
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Range("A1:A" & lastrow)
For Each cell In rng
If cell.Value = "" Then
cell.Value = cell.Offset(0, 1).Value
End If
Next cell
End Sub
答案 1 :(得分:3)
你可以试试这个
Sub main()
With ActiveSheet.UsedRange.Columns("A")
If WorksheetFunction.CountBlank(.Cells) > 0 Then
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=RC[1]"
.Value = .Value
End If
End With
End Sub
答案 2 :(得分:2)
Sub movecells()
Dim usedrows As Integer
Dim tmpval As String
Dim i As Integer
usedrows = UsedRange.Rows.Count
For i = 1 To usedrows Step 1
If Cells(i, 1).Value = "" And Cells(i, 2).Value <> "" Then
Cells(i, 1).Value = Cells(i, 2).Value
Cells(i, 2).Value = ""
End If
Next i
End Sub