Loop column A then copy row data to next all blank row

SamKhem

Board Regular
Joined
Mar 18, 2024
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Dear Senior member
I would like disturb you again. as run vba loop column A then meet first row non blank then copy to blank row as below.
DataResult
1PD210561PD21056
100LD21053100LD21053
100LD21053
100LD21053
100LD21053
100LD21053
100LD21053
100LD21053
100LD21056100LD21056
100LD21058100LD21058
100LD21065100LD21065
100LD21065
100LD21065
100LD21065
100LD21065
100LD21065
100LD21065
100LD21065
100LD21070100LD21070
100LD21070
100LD21070
100LD21070
100LD21070
100LD21070
100LD21070
100LD21070
100LD21070
100LD21070
100LD21070
100PD21053100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21053
100PD21056100PD21056
100PD21056100PD21056
100PD21058100PD21058
100PD21058100PD21058
100PD21065100PD21065
100PD21065
100PD21065
100PD21065
100PD21065
100PD21065
100PD21065
100PD21065
100PD21065
100PD21065
100PD21065100PD21065
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Would

Excel Formula:
=IF(A2<>"",A2,B1)

count as a solution?
 
Upvote 0
Here's VBA option.
VBA Code:
Sub fillDown()
    Dim a, b
    Dim ws As Worksheet
    Dim i As Long
    Set ws = ThisWorkbook.Sheets("Sheet2")
    
    a = ws.Range("A2:A" & ws.Cells(Rows.Count, "A").End(xlUp).Row)
    ReDim b(1 To UBound(a, 1), 1 To 1)
    For i = 1 To UBound(a, 1)
        If a(i, 1) = "" Then
            b(i, 1) = b(i - 1, 1)
        Else
            b(i, 1) = a(i, 1)
        End If
    Next i
    
    ws.Range("B2").Resize(UBound(b, 1), 1).Value = b
End Sub
 
Upvote 0
Solution
Thank for this vba code.
Here's VBA option.
VBA Code:
Sub fillDown()
    Dim a, b
    Dim ws As Worksheet
    Dim i As Long
    Set ws = ThisWorkbook.Sheets("Sheet2")
   
    a = ws.Range("A2:A" & ws.Cells(Rows.Count, "A").End(xlUp).Row)
    ReDim b(1 To UBound(a, 1), 1 To 1)
    For i = 1 To UBound(a, 1)
        If a(i, 1) = "" Then
            b(i, 1) = b(i - 1, 1)
        Else
            b(i, 1) = a(i, 1)
        End If
    Next i
   
    ws.Range("B2").Resize(UBound(b, 1), 1).Value = b
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,869
Messages
6,162,530
Members
451,773
Latest member
ssmith04

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top