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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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