Macro to Autofill all blank cells in a column

dencarter

New Member
Joined
Apr 20, 2010
Messages
7
Hi guys -

I have another Excel macro problem.

I have a spreadsheet with a column that's formatted like this:

6575
blank
blank
blank
4457
blank
blank
blank
blank
3355
blank
blank


Obviously the 'blanks' are blank cells and there are about 10,000 rows in the sheet.

I would like to autofill the blank cells so that the value above them is repeated, so it would actually look like this:

6575
6575
6575
6575
4457
4457
4457
4457
4457
3355
3355
3355

I'm sorry if this is a really obvious one, but I've searched and can't find anything to help me... If anyone can point me in the right direction I would really appreciate it.

Cheers,
Den
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try

Code:
Sub FillBl()
Dim LR As Long
LR = ActiveSheet.UsedRange.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("A1:A" & LR)
    With .SpecialCells(xlCellTypeBlanks)
        .FormulaR1C1 = "=R[-1]C"
    End With
    .Value = .Value
End With
End Sub
 
Upvote 0
Assuming your list starts at A2, insert a column next to it (which will become column B), put this formula in B2,

=IF(A2="",B1,A2)

then copy and paste this formula all the way down column B until you get to the end of your list. You will then have your desired list in column B. If necessary you can copy this and paste special values over the list in column A.

Any help?
 
Upvote 0
Try

Code:
Sub FillBl()
Dim LR As Long
LR = ActiveSheet.UsedRange.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("A1:A" & LR)
    With .SpecialCells(xlCellTypeBlanks)
        .FormulaR1C1 = "=R[-1]C"
    End With
    .Value = .Value
End With
End Sub


Hi there -

Thanks for taking the time to look at this...

I changed
With Range("A1:A" & LR)
to
With Range("C1:C" & LR)
because the column with the data is actually C.

When I run the Macro I get:

Run-time error '1004':
No cells were found

Any ideas?
 
Upvote 0
Are they blanks or do they contain spaces. Try selecting all the blanks, hitting the Delete key, then running the macro.
 
Upvote 0
Are they blanks or do they contain spaces. Try selecting all the blanks, hitting the Delete key, then running the macro.

Great - progress! But now I just get #REF! in each of the newly-filled cells... Sorry to be a pain, really appreciate your time.
 
Upvote 0
I've just tried this

Code:
Sub FillBl()
Dim LR As Long
LR = ActiveSheet.UsedRange.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
With Range("C1:C" & LR)
    With .SpecialCells(xlCellTypeBlanks)
        .FormulaR1C1 = "=R[-1]C"
    End With
    .Value = .Value
End With
End Sub

with your example data in column C and it worked.

If your workbook doesn't contain sensitive information, could you upload it to www.box.net and provide a link.
 
Upvote 0
I tried Peter's code and got the #REF! errors if the first cell was blank (ie C1 was blank), I have no idea why it would do this but putting a heading in C1 cured it!?

?
 
Upvote 0
How about this? Assuming column A has your data, press F5, Click special, choose blank cells. Your cursor should be in the first blank cell (in my case B1). Type the formula "=A1" and hit control enter.

You may have to manually do the last occurrence...
 
Upvote 0
I tried Peter's code and got the #REF! errors if the first cell was blank (ie C1 was blank), I have no idea why it would do this but putting a heading in C1 cured it!?

?

Hi guys - this solved the problem perfectly! It was just because there were blank rows above the data... Strange but I am now very happy! Thank you VoG - brilliant!

xlHammer - your =IF solution also worked a treat.

Thanks very much!
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,605
Members
449,174
Latest member
ExcelfromGermany

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