Using Names in Macros

StewartS

Board Regular
Joined
Feb 24, 2002
Messages
217
I am writing a macro which selects a varible range of data and then performs a pivot table on it.

In order to select the range in the pivot table I was going create a name for the range in the macro. I am using varibles to select the first and last cell in the range.

See below

Dim startcell
Dim endcell

Range("A1").Select
startcell = ActiveCell.Address
Selection.End(xlDown).Select
Selection.End(xlRight).Select
endcell = ActiveCell.Address

Range(startcell, endcell).Select
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
"=DOWNLOAD!R1C1:R5253C7"

Instead of the "=DOWNLOAD!R1C1:R5253C7" I want to use the startcell, endcell range.

Can anybody help please.

Stewart
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
ActiveWorkbook.Names.Add Name:="Data", RefersToR1C1:= _
selection


Cheers,

Nate
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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