/ / copiar as células anteriores com 2 colunas de uma só vez? - excel, vba, excel-vba

copiar as células anteriores com 2 colunas de uma só vez? - excel, vba, excel-vba

insira a descrição da imagem aqui

é possível copiar os valores das células, 2 colunas ao mesmo tempo (os valores são diferentes em ambas as colunas = strings). Agora eu estou fazendo isso separadamente.

1:

 Do Until ActiveCell.Row >= LastRow
If Trim(ActiveCell.Offset(1, 0)) = "" Then
ActiveCell.Offset(1, 0).Value = ActiveCell
End If
ActiveCell.Offset(1, 0).Select
Loop

e depois novamente para a terceira coluna

    Cells(FirstRow + 2, 2).Select
Do Until ActiveCell.Row >= LastRow
If Trim(ActiveCell.Offset(1, 0)) = "" Then
ActiveCell.Offset(1, 0).Value = ActiveCell
End If
ActiveCell.Offset(1, 0).Select
Loop

Na verdade eu codifiquei isso abaixo, vai simultaneamente, mas tenho uma importância que é lento

Sub Kopi()
Dim i, y As Integer
For i = 1 To 100
For y = 1 To 100
If Trim(Cells(i + 1, 1)) = "" And Trim(Cells(y + 1, 2)) = "" Then
Cells(i + 1, 1).Value = Cells(i, 1)
Cells(y + 1, 2).Value = Cells(y, 2)
End If

Next y
Next i
End Sub

Respostas:

1 para resposta № 1

É isto que você precisa? Ele percorre suas células vazias no intervalo determinado (A1:B10) e define quaisquer espaços em branco iguais ao valor acima

Sub Test()
Dim rng As Range, r As Range
Set rng = ThisWorkbook.Worksheets("Sheet1").Range("A1:B10").SpecialCells(xlCellTypeBlanks)

For Each r In rng
If Not r.Row = 1 Then r.Value = r.Offset(-1, 0).Value
Next r
End Sub