ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to create a varying named range (https://www.excelbanter.com/excel-programming/406172-macro-create-varying-named-range.html)

[email protected]

Macro to create a varying named range
 
What I want to do is have a macro that selects all cells containing
data, creates a range and names it "Print_Area" sounds simple, but I
cannot get it to work

ActiveSheet.UsedRange.Select
ActiveWorkbook.Names.Add Name:="Print_Area", RefersToR1C1:= _
"=R396070CS01!R1C1:R38C17"

Ive got that, which works fine, however, i need to to be run in many
spreadsheets, with varying sheet names, and varying cell ranges.

Ideas...??

reklamo

Macro to create a varying named range
 
Try following:

ActiveSheet.UsedRange.Select
Selection.Name = "Print_Area"

regards
reklamo


" wrote:

What I want to do is have a macro that selects all cells containing
data, creates a range and names it "Print_Area" sounds simple, but I
cannot get it to work

ActiveSheet.UsedRange.Select
ActiveWorkbook.Names.Add Name:="Print_Area", RefersToR1C1:= _
"=R396070CS01!R1C1:R38C17"

Ive got that, which works fine, however, i need to to be run in many
spreadsheets, with varying sheet names, and varying cell ranges.

Ideas...??


Dave Peterson

Macro to create a varying named range
 
Won't clearing the print area let excel just use the usedrange?

Dim Wks as worksheet
for each wks in activeworkbook.worksheets
wks.PageSetup.PrintArea = ""
next wks

But if you want...

Dim Wks as worksheet
for each wks in activeworkbook.worksheets
wks.usedrange.name = "'" & wks.name & "'!Print_Area"
next wks


wrote:

What I want to do is have a macro that selects all cells containing
data, creates a range and names it "Print_Area" sounds simple, but I
cannot get it to work

ActiveSheet.UsedRange.Select
ActiveWorkbook.Names.Add Name:="Print_Area", RefersToR1C1:= _
"=R396070CS01!R1C1:R38C17"

Ive got that, which works fine, however, i need to to be run in many
spreadsheets, with varying sheet names, and varying cell ranges.

Ideas...??


--

Dave Peterson


All times are GMT +1. The time now is 11:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com