Fill cells with data by VBA

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
21,834
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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
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,214,638
Messages
6,120,674
Members
448,977
Latest member
moonlight6

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