Auto Fill Macro Not Working Properly

J

Jason

Hi,

I used a macro that I found through this newsgroup that
auto fills down when you've got spaces in Column A that
need filling with a prior value. It looks like this.

Sub FillBlanksColumnA()
Application.ScreenUpdating = False
Extent = Cells.Rows.Count
For i = 2 To Extent
If Cells(i, 1) = "" Then Cells(i, 1) = Cells(i - 1, 1)
Next i
End Sub

My problem is that this continues onto line 65000+. How
can I revise this macro to stop when there is a blank or
no value in Col B? Or can it be revised to say stop at
line 2000?

Thanks in advance.

Jason
 
M

MJP

Jason,

If you want to limit it to 2000 rows, just change the line For i = 2 to
Extent to read For i = 2 to 2000

Alternatively if you want it to keep going until it finds a blank row in
column B try this variation:

Sub FillBlanksColumnA()
Application.ScreenUpdating = False
i = 2
Do Until Cells(i, 2).Value = ""
If Cells(i, 1) = "" Then Cells(i, 1) = Cells(i - 1, 1)
i = i + 1
Loop
End Sub

HTH

Mitch
 
K

Kevin

I like this macro, there would be times where this would be handy. Where do
I add this macro?
thanks for you help

Kevin
 
Top