macro relative position

Tody03

New Member
Joined
Jun 21, 2014
Messages
48
I have data that looks like that:
a1
b5
c3
d7
e2
f2
g
h
i
j


<colgroup><col span="2"></colgroup><tbody>
</tbody>
I want to fill the missing data in column b. that will be paralel to column a.
I wrote the attached macro
Range("B1").Select
Selection.End(xlDown).Select
Range("B7").Select
ActiveCell.FormulaR1C1 = "0"
Range("B8").Select
ActiveCell.FormulaR1C1 = "=R[-1]C"
Range("B8").Select
Selection.AutoFill Destination:=Range("B8:B16")
Range("B8:B16").Select
End Sub

my problem is that this macro does not work properly if column b is shorter or longer. How can i correct the macro that regardless the column length it will fill he missing data.
Thanks
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How about
Code:
Sub Tody03()
   With Range("B:B")
      .SpecialCells(xlBlanks)(1).Value = 0
      .SpecialCells(xlBlanks).FormulaR1C1 = "=r[-1]c"
   End With
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,185
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