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,
[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]Mango[/TD]
[/TR]
[TR]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65"]Apple[/TD]
[/TR]
[TR]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65"]Orange[/TD]
[/TR]
[TR]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65"] [/TD]
[/TR]
[TR]
[TD="class: xl65"]Pear[/TD]
[/TR]
</tbody>[/TABLE]


Is there a VBA that can help populate the blank cells above to become the following:
[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]Mango[/TD]
[/TR]
[TR]
[TD="class: xl65"]Apple[/TD]
[/TR]
[TR]
[TD="class: xl65"]Apple[/TD]
[/TR]
[TR]
[TD="class: xl65"]Apple[/TD]
[/TR]
[TR]
[TD="class: xl65"]Orange[/TD]
[/TR]
[TR]
[TD="class: xl65"]Orange[/TD]
[/TR]
[TR]
[TD="class: xl65"]Orange[/TD]
[/TR]
[TR]
[TD="class: xl65"]Pear[/TD]
[/TR]
[TR]
[TD="class: xl65"]Pear[/TD]
[/TR]
[TR]
[TD="class: xl65"]Pear



[/TD]
[/TR]
</tbody>[/TABLE]


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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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