Fill cells with data by VBA

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,648
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Hi All
I currently have 2700 rows of data that I need to repopulate.
What I am trying to do is:
Column "D" has a 4 digit number on each row.
If the row at column "D" is blank, I want the macro to use the last previous 4 digit number until it encounters a populated row.
So, if D1,D2,D3, have the number 5150 in them and D4:D11 are blank, the macro will insert 5150, if D12,D13,D14, have the number 2468 in them and D15:D25 are blank, the macro will insert 2468, etc, etc.
Any assistance would be greatly appreciated.

Regards
Michael M
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
How's this:

<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> foo()<br>    <SPAN style="color:#00007F">Dim</SPAN> c <SPAN style="color:#00007F">As</SPAN> Range<br>        <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> c <SPAN style="color:#00007F">In</SPAN> Range([D1], Cells(Rows.Count, "D").End(xlUp))<br>            <SPAN style="color:#00007F">If</SPAN> LenB(c) = 0 <SPAN style="color:#00007F">Then</SPAN> c.Value = c.Offset(-1).Value<br>        <SPAN style="color:#00007F">Next</SPAN> c<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>

HTH,
 
Upvote 0

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,648
Office Version
  1. 365
  2. 2019
  3. 2013
  4. 2007
Platform
  1. Windows
Hi Smitty
What can I say.....perfect !!
I am constantly in awe of the power of this site and its subscribers.

Many thanks my friend.

Regards
Michael M
 
Upvote 0

Forum statistics

Threads
1,195,628
Messages
6,010,772
Members
441,568
Latest member
abbyabby

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
Top