Autofill Column B based on the dynamic range of Column A

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello All,

Using the macro recorder, I have this code below that currently autofills down to row 444.

Code:
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=TEXT(RC[-1],""MMMM"")"
    Range("B2").Select
    Selection.AutoFill Destination:=Range("B2:B444")


The only problem is that the next time I run this macro, the row count will be different. I would like it to stop autofilling Column B once it is equal to the last row of data in column A.



I did a search and saw this code here from VoG...
Code:
Dim LR As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
Range("I4").AutoFill Destination:=Range("I4:I" & LR)

...and tried this here...


Code:
Sub Autofill()
 
Dim LR As Long
 
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=TEXT(RC[-1],""MMMM"")"
    Range("B2").Select
LR = Range("A" & Rows.Count).End(xlUp).Row
Range("B2").AutoFill Destination:=Range("B2:B" & LR)
 
End Sub

But it didn't work.

Can anyone help me with this one?

Thanks :)
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this.
Code:
Dim LR As Long
 
    LR = Range("A" & Rows.Count).End(xlUp).Row
 
    Range("B2:B" & LR).FormulaR1C1 = "=TEXT(RC[-1],""MMMM"")"
 
Upvote 0
VoG has a lot to answer for :)

Try

Code:
Sub aaaatree()
Dim LR3 As Long
LR3 = Range("A" & Rows.Count).End(xlUp).Row
Range("B2").FormulaR1C1 = "=TEXT(RC[-1],""MMMM"")"
Range("B2").AutoFill Destination:=Range("B2:B" & LR)
End Sub
 
Upvote 0
VoG and Norie,

They both worked awesome. (Except, VoG...I un-intentionally threw you a curve ball and edited my post and renamed LR to LR3 and your last line of code was "LR", my fault though!).


Thanks to the both of you!
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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