Change Range To Recorded Macro

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,783
Office Version
  1. 365
Platform
  1. Windows
I have recorded a macro that I will run every time I open the spreadsheet. Problem is that the range will change each time i run it. What do I need to change in the macro to accommodate the extended range each time please? It will also need to be run on sheet 1 each time looking at sheet 4.

Code:
Sub Macro2()
'
' Macro2 Macro
'

'
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-17],Sheet4!C[-27]:C[-26],2,0)"
    Selection.AutoFill Destination:=Range("AB2:AB437")
    Range("AB2:AB437").Select
    Columns("AB:AB").EntireColumn.AutoFit
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
like this ?


VBA Code:
Sub Dazzawm()

Dim ls As Long


ls = Range("K" & Rows.Count).End(xlUp).Row

    With Range("AB2:AB" & ls)

    .Formula2 = "=VLOOKUP(K2,Sheet4!A:B,2,0)"
    .Copy
    .PasteSpecial xlPasteValues
    .EntireColumn.AutoFit

    End With
 
Application.CutCopyMode = False

End Sub
 
Upvote 0
Solution
like this ?


VBA Code:
Sub Dazzawm()

Dim ls As Long


ls = Range("K" & Rows.Count).End(xlUp).Row

    With Range("AB2:AB" & ls)

    .Formula2 = "=VLOOKUP(K2,Sheet4!A:B,2,0)"
    .Copy
    .PasteSpecial xlPasteValues
    .EntireColumn.AutoFit

    End With
 
Application.CutCopyMode = False

End Sub
That seems to do it, much obliged squire.
 
Upvote 0
As the next step you should be able to

Replace:
VBA Code:
    .Copy
    .PasteSpecial xlPasteValues

With:
VBA Code:
    .Value = .Value
 
Upvote 0

Forum statistics

Threads
1,223,856
Messages
6,175,027
Members
452,604
Latest member
cballetti

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