VBA loop through each column and filling the empty rows by repeating row values: given the row count as highest rows in any of the column

bmbalamurali

New Member
Joined
Oct 3, 2013
Messages
6
Hello Experts,

I was trying to do a task as described below in VBA (complete confusions in array and looping as per my logic), could you please help with a VBA code.

example:
The first row is column heading
1. Sheet have 10 columns, each has filled rows but not equally.
2. Need to fill all the blank rows having 7 as the limit in all columns ( because 7 is highest row count in column1 comparing all columns)
3. The blanks in each column to filled by repeating the value in top to bottom order until reaching the limit row

Before:
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD]players[/TD]
[TD]ground[/TD]
[TD]ball[/TD]
[TD]camera[/TD]
[TD]grass[/TD]
[TD]t-shirt[/TD]
[TD]boots[/TD]
[TD]drinks[/TD]
[TD]refree[/TD]
[TD]cup[/TD]
[/TR]
[TR]
[TD]cena[/TD]
[TD]grass[/TD]
[TD]leather[/TD]
[TD]dslr[/TD]
[TD]green[/TD]
[TD]neck[/TD]
[TD]nike[/TD]
[TD]coke[/TD]
[TD]somebody[/TD]
[TD]world[/TD]
[/TR]
[TR]
[TD]messi[/TD]
[TD]mud[/TD]
[TD]plastic[/TD]
[TD]cannon[/TD]
[TD]white[/TD]
[TD]collar[/TD]
[TD]reebok[/TD]
[TD]pepsi[/TD]
[TD]nobody[/TD]
[TD]europa[/TD]
[/TR]
[TR]
[TD]ronaldo[/TD]
[TD][/TD]
[TD]sponge[/TD]
[TD]nikon[/TD]
[TD][/TD]
[TD]red[/TD]
[TD][/TD]
[TD]tea[/TD]
[TD]anybody[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]dravid[/TD]
[TD][/TD]
[TD]rubber[/TD]
[TD][/TD]
[TD][/TD]
[TD]blue[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]bolt[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]halfsleeves[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]bala[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

After: expected result

[TABLE="width: 924"]
<colgroup><col><col><col><col><col><col><col><col><col><col></colgroup><tbody>[TR]
[TD]players[/TD]
[TD]ground[/TD]
[TD]ball[/TD]
[TD]camera[/TD]
[TD]grass[/TD]
[TD]t-shirt[/TD]
[TD]boots[/TD]
[TD]drinks[/TD]
[TD]refree[/TD]
[TD]cup[/TD]
[/TR]
[TR]
[TD]cena[/TD]
[TD]grass[/TD]
[TD]leather[/TD]
[TD]dslr[/TD]
[TD]green[/TD]
[TD]neck[/TD]
[TD]nike[/TD]
[TD]coke[/TD]
[TD]somebody[/TD]
[TD]world[/TD]
[/TR]
[TR]
[TD]messi[/TD]
[TD]mud[/TD]
[TD]plastic[/TD]
[TD]cannon[/TD]
[TD]white[/TD]
[TD]collar[/TD]
[TD]reebok[/TD]
[TD]pepsi[/TD]
[TD]nobody[/TD]
[TD]europa[/TD]
[/TR]
[TR]
[TD]ronaldo[/TD]
[TD]grass[/TD]
[TD]sponge[/TD]
[TD]nikon[/TD]
[TD]green[/TD]
[TD]red[/TD]
[TD]nike[/TD]
[TD]tea[/TD]
[TD]anybody[/TD]
[TD]world[/TD]
[/TR]
[TR]
[TD]dravid[/TD]
[TD]mud[/TD]
[TD]rubber[/TD]
[TD]dslr[/TD]
[TD]white[/TD]
[TD]blue[/TD]
[TD]reebok[/TD]
[TD]coke[/TD]
[TD]somebody[/TD]
[TD]europa[/TD]
[/TR]
[TR]
[TD]bolt[/TD]
[TD]grass[/TD]
[TD]leather[/TD]
[TD]cannon[/TD]
[TD]green[/TD]
[TD]halfsleeves[/TD]
[TD]nike[/TD]
[TD]pepsi[/TD]
[TD]nobody[/TD]
[TD]world[/TD]
[/TR]
[TR]
[TD]bala[/TD]
[TD]mud[/TD]
[TD]plastic[/TD]
[TD]nikon[/TD]
[TD]white[/TD]
[TD]neck[/TD]
[TD]reebok[/TD]
[TD]tea[/TD]
[TD]anybody[/TD]
[TD]europa[/TD]
[/TR]
[TR]
[TD]cena[/TD]
[TD]grass[/TD]
[TD]sponge[/TD]
[TD]dslr[/TD]
[TD]green[/TD]
[TD]collar[/TD]
[TD]nike[/TD]
[TD]coke[/TD]
[TD]somebody[/TD]
[TD]world[/TD]
[/TR]
</tbody>[/TABLE]


hope i put my question understandable? please do come back for any clarification.
 

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.
Code:
Sub FT()
Dim col%, rng As Range
For col = 1 To 10
    Set rng = Range(Cells(2, col), Cells(Rows.Count, col).End(xlUp))
    rng.AutoFill Destination:=Range(Cells(2, col), Cells(8, col))
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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