Fill in blank cells in a range

John60

Board Regular
Joined
Jan 25, 2012
Messages
101
Hi there. Need some help please.

I would like to get some code that will fill blanks in a range.

Forgive me if I have not used the board facilities properly. In the following table I need each blank cell in column B to be filled with the text from the preceding cell that has text in it.

i.e. B2 to be populated with "text1". Cells B4:B6 to be populated with "text2".

The code needs to know that row 9 is the last row to populate.

Thanks in advance

AB
1headtext1
2acc
3headtext2
4acc
5fry
6oth
7headtext3
8acc
9oth
10

<TBODY>
</TBODY>
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You don't really need code for that...

Highlight Column B
Press CTRL + G
Click Special
Select Blanks
Click OK
Press =
Press UP Arrow
Press CTRL + ENTER


Hope that helps.
 
Upvote 0
You don't really need code for that...

Highlight Column B
Press CTRL + G
Click Special
Select Blanks
Click OK
Press =
Press UP Arrow
Press CTRL + ENTER


Hope that helps.

Brilliant! Never knew about that. Thank you very much.
 
Upvote 0
Glad to help, thanks for the feedback.

Maybe you can help with this bit of my code too.

I have declared lrow as long and identified row 9 as the last row to be populated.

I have written:

Range("E3:E " & lrow & " ").Select

The syntax is wrong and I don't know why. Can you help?
 
Upvote 0
Range("E3:E" & lrow).Select


Though it's rarely necessary to select ranges to manipulate them..
You can refer to them directly
Range("E3:E" & lrow).Value = "Hello"
 
Upvote 0
Range("E3:E" & lrow).Select


Though it's rarely necessary to select ranges to manipulate them..
You can refer to them directly
Range("E3:E" & lrow).Value = "Hello"

So how should this look?

Range("E3:E" & lrow).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.FormulaR1C1 = "=R[-1]C"
 
Upvote 0
General rule of thumb for removing Select and Selection...

Work from the bottom UP..
If you see Selection, just replace that with whatever was previously selected.

so this
Range("E3:E" & lrow).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection
.FormulaR1C1 = "=R[-1]C"

becomes

Range("E3:E" & lrow).Select
Selection
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"

becomes

Range("E3:E" & lrow).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"


Hope that helps.
 
Upvote 0
General rule of thumb for removing Select and Selection...

Work from the bottom UP..
If you see Selection, just replace that with whatever was previously selected.

so this
Range("E3:E" & lrow).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection
.FormulaR1C1 = "=R[-1]C"

becomes

Range("E3:E" & lrow).Select
Selection
.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"

becomes

Range("E3:E" & lrow).SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"


Hope that helps.

Genius!

I don't think I will ever get to that level.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,213,532
Messages
6,114,176
Members
448,554
Latest member
Gleisner2

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