该代码有效,但在移动单元格时会将其2粘贴到底部单元格下方。基本上我只需要它们粘贴而没有任何空单元格
Dim rw11 As Long
Dim lastrow11 As Long
lastrow11 = Worksheets("Sheet1").UsedRange.Rows(Worksheets("Sheet1").UsedRange.Rows.Count).row
For rw11 = 1000 To 1 Step -1
With Worksheets("Sheet1")
' Check if "save" appears in the value anywhere.
If .Cells(rw11, 2).Value Like "*Player Number*" Then
' Cut the value and then blank the source and shift up
.Cells(rw11, 2).Cut Destination:=Worksheets("Sheet1").Cells(lastrow11, 3)
.Cells(rw11, 2).Delete (xlUp)
End If
End With
lastrow11 = Worksheets("Sheet1").UsedRange.Rows(Worksheets("Sheet1").UsedRange.Rows.Count).row + 1
Next
答案 0 :(得分:0)
这有效吗?您完全不需要最后一行变量。我能想到的让您的代码无法正常工作的唯一原因是,它被定义了两次,并且UsedRange不可靠,因为它可以“记住”以前的单元格内容。
Sub x()
Dim rw11 As Long
For rw11 = 1000 To 1 Step -1
With Worksheets("Sheet1")
If .Cells(rw11, 2).Value Like "*Player Number*" Then
.Cells(rw11, 2).Cut Destination:=.Cells(Rows.Count, 3).End(xlUp)(2)
.Cells(rw11, 2).Delete (xlUp)
End If
End With
Next
End Sub