VBA Autofill Variable Range

mwinte10

New Member
Joined
Oct 22, 2010
Messages
6
Hello,

I am using MSExcel 2003 and have recorded a macro that I would like to edit but am coming up short on a good solution. The sub routine will insert columns and convert data from other columns using the UPPER function.

I have copied out a portion of the macro below and feel that if I can solve the problem I am having with this, I will be able to use the solution in other parts of the code.

Using the example below, the Autofill ends up filling all of the way down the page (to row 65536). The actual data on the worksheet ends on a variable row, different every month. I want to base my Autofill range to be as many rows as the data in column A. Column A is filled with the same text value until it ends. This should work just as if I double clicked the bottom left corner of the selected cell when working directly in a worksheet. Does anybody have any ideas?

Code:
Sub CC_Edit_ColB()
 
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
    Range("B1").Select
    ActiveCell.FormulaR1C1 = "LAST_NAME"
    Range("B2").Select
    ActiveCell.FormulaR1C1 = "=UPPER(RC[12])"
    Range("B2").Select
    Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown))
 
End Sub

Thank you.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi. Try this

Code:
Sub CC_Edit_ColB()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Columns("B").Insert
Range("B1").Value = "LAST_NAME"
Range("B2:B" & LR).FormulaR1C1 = "=UPPER(RC[12])"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,865
Members
452,948
Latest member
UsmanAli786

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