我想首先在colunm G中找到bank单元格,然后从F列中选择相同的单元格。然后从该单元格中选择数据以填充单元格并复制。然后再次来到G列的空白单元格并粘贴值。 Pl帮助我。
Sub copyy2()
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
Dim A As Long
Dim otherCol As Integer
Dim cell As Excel.Range
sourceCol = 8 'column H has a value of 8
otherCol = sourceCol - 1 'column before H
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
'for every row, find the first blank cell and select it
With Sheets("sheet1")
For currentRow = 1 To rowCount
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
A = currentRow
'cell = Cells(currentRow, sourceCol)
Exit For
End If
Next
'A = cell.Row
Cells(A, otherCol).Select
Range(Selection, Cells(A, otherCol).End(xlDown)).Select
Selection.copy
Range(Selection, Cells(A, sourceCol)).Select
End With
End Sub
答案 0 :(得分:0)
尝试,
dim rng as range
With Sheets("sheet1")
set rng = .columns("G").specialcells(xlcelltypeblanks).cells(1)
if .cells(.rows.count, "F").end(xlup).row > rng.row then
.range(rng.offset(0, -1), .cells(.rows.count, "F").end(xlup)).copy _
destination:=rng
end if
end with