VBA to fill cells with values

afrobea_r

Board Regular
Joined
Aug 16, 2015
Messages
76
Dear Excel community,

Currently I have a column that looks like this,
Mango
Apple
Orange
Pear

<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>


Is there a VBA that can help populate the blank cells above to become the following:
Mango
Apple
Apple
Apple
Orange
Orange
Orange
Pear
Pear
Pear




<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>
</tbody>


My existing formula is as such but it only will fill if I select the column up till the row I want
On Error Resume Next
With Selection.SpecialCells(xlCellTypeBlanks)
.FormulaR1C1 = "=R[+1]C"
.Value = .Value
End With
End Sub

Help greatly appreciated!! Thank you!!
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try either

Code:
   With Range("A:A").SpecialCells(xlCellTypeBlanks)
      .FormulaR1C1 = "=R[-1]C"
      .Value = .Value
    End With
OR for a specific range

Code:
    With Range("A[color=red]1[/color]:A[color=red]100[/color]").SpecialCells(xlCellTypeBlanks)
      .FormulaR1C1 = "=R[-1]C"
      .Value = .Value
    End With
 
Upvote 0
Hi Michael thanks for your help, but the code only populates the rest of the cells based on the the first row cell value, and not according to the different values that are present in the column. Is there a work around?
 
Upvote 0
How about
Code:
Sub FillBlanks()
   With Range("A1:A100")
      On Error Resume Next
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[1]c"
      On Error GoTo 0
      .Value = .Value
   End With
End Sub
 
Upvote 0
You need to try this it will definitely work

With Range("A:A").SpecialCells(xlCellTypeBlanks)
On error resume next
.FormulaR1C1 = "=R[-1]C"
.Value =cells("=R[-1]C").value
End With
 
Upvote 0
Not sure if you are aware, but you are replying to a thread that is almost 2 years old. ;)
Also you solution will leave the formula in the cells, rather than converting it to a value.
 
Upvote 0
I am not professional
So i am not sure
But you need to use it for once
Thank you
 
Last edited by a moderator:
Upvote 0
I don't need to try it. I can tell just by looking at the code that it will leave the formula in the cells.
 
Upvote 0

Forum statistics

Threads
1,215,737
Messages
6,126,575
Members
449,318
Latest member
Son Raphon

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