Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Don Don is offline
external usenet poster
 
Posts: 487
Default Setting a range value to the last cell in active worksheet.

I am generating a dynamic pivot table that is based on an Excel Worksheet.

I can do what I want manually, but what I need to do is to set a Named Range field to the last poplulated cell on the worksheet, so that I can pass a named range field to the pivot table wizard.


-- my progress so far ...
Of course, the following will position me to the last cell on the sheet

Range("A1").Select
Selection.End(xlToRight).Select
Selection.End(xlDown).Select

Next, I create a range called "Database" that defines the area of the worksheet that I want to define...

ActiveWorkbook.Names("Database").Delete
ActiveWorkbook.Names.Add Name:="database", RefersToR1C1:= _
"=Sheet1!R1C1:last"

Then I pass this named range ("Database") to the pivot table wizard ...

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Database").CreatePivotTable TableDestination:="", TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion10

The problem I have is that "last" named range is static, and has been created manually. If I try to record the macro, it creates a static range. I need to dynamically assign the current cell (ie: the last cell on the worksheet) and put it in the named range "last"

Alternately, I would like to dynamically define the name "Database" as the area of the worksheet that is populated.


Thanks in advance,

Don


  #2   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Setting a range value to the last cell in active worksheet.

Try this after Selection.end(xldown).select

a=activecell.address
Names.Add Name:="Last", RefersTo:="=(yoursheetname)!" & a

Best of luck
DavidC

-----Original Message-----
I am generating a dynamic pivot table that is based on an

Excel Worksheet.

I can do what I want manually, but what I need to do is

to set a Named Range field to the last poplulated cell on
the worksheet, so that I can pass a named range field to
the pivot table wizard.


-- my progress so far ...
Of course, the following will position me to the last

cell on the sheet

Range("A1").Select
Selection.End(xlToRight).Select
Selection.End(xlDown).Select

Next, I create a range called "Database" that defines the

area of the worksheet that I want to define...

ActiveWorkbook.Names("Database").Delete
ActiveWorkbook.Names.Add Name:="database",

RefersToR1C1:= _
"=Sheet1!R1C1:last"

Then I pass this named range ("Database") to the pivot

table wizard ...

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,

SourceData:= _
"Database").CreatePivotTable

TableDestination:="", TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion10

The problem I have is that "last" named range is static,

and has been created manually. If I try to record the
macro, it creates a static range. I need to dynamically
assign the current cell (ie: the last cell on the
worksheet) and put it in the named range "last"

Alternately, I would like to dynamically define the

name "Database" as the area of the worksheet that is
populated.


Thanks in advance,

Don


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Setting a range value to the last cell in active worksheet.

You don't need to delete the name Database. When you redefine it as below,
the new definition replaces the old.

Worksheets("sheet1").Range("A1").CurrentRegion.Nam e = "Database"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Database").CreatePivotTable TableDestination:="",
TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion10


--
Regards,
Tom Ogilvy


"Don" wrote in message
...
I am generating a dynamic pivot table that is based on an Excel Worksheet.

I can do what I want manually, but what I need to do is to set a Named

Range field to the last poplulated cell on the worksheet, so that I can pass
a named range field to the pivot table wizard.


-- my progress so far ...
Of course, the following will position me to the last cell on the sheet

Range("A1").Select
Selection.End(xlToRight).Select
Selection.End(xlDown).Select

Next, I create a range called "Database" that defines the area of the

worksheet that I want to define...

ActiveWorkbook.Names("Database").Delete
ActiveWorkbook.Names.Add Name:="database", RefersToR1C1:= _
"=Sheet1!R1C1:last"

Then I pass this named range ("Database") to the pivot table wizard ...

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Database").CreatePivotTable TableDestination:="",

TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion10

The problem I have is that "last" named range is static, and has been

created manually. If I try to record the macro, it creates a static range.
I need to dynamically assign the current cell (ie: the last cell on the
worksheet) and put it in the named range "last"

Alternately, I would like to dynamically define the name "Database" as the

area of the worksheet that is populated.


Thanks in advance,

Don




  #4   Report Post  
Posted to microsoft.public.excel.programming
Don Don is offline
external usenet poster
 
Posts: 487
Default Setting a range value to the last cell in active worksheet.

Thank you very much Tom, this did exactly what I was looking for ...

It's nice to know that in VB, someone has already done it before.

Take Care

Don

"Tom Ogilvy" wrote:

You don't need to delete the name Database. When you redefine it as below,
the new definition replaces the old.

Worksheets("sheet1").Range("A1").CurrentRegion.Nam e = "Database"
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Database").CreatePivotTable TableDestination:="",
TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion10


--
Regards,
Tom Ogilvy


"Don" wrote in message
...
I am generating a dynamic pivot table that is based on an Excel Worksheet.

I can do what I want manually, but what I need to do is to set a Named

Range field to the last poplulated cell on the worksheet, so that I can pass
a named range field to the pivot table wizard.


-- my progress so far ...
Of course, the following will position me to the last cell on the sheet

Range("A1").Select
Selection.End(xlToRight).Select
Selection.End(xlDown).Select

Next, I create a range called "Database" that defines the area of the

worksheet that I want to define...

ActiveWorkbook.Names("Database").Delete
ActiveWorkbook.Names.Add Name:="database", RefersToR1C1:= _
"=Sheet1!R1C1:last"

Then I pass this named range ("Database") to the pivot table wizard ...

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"Database").CreatePivotTable TableDestination:="",

TableName:="PivotTable2" _
, DefaultVersion:=xlPivotTableVersion10

The problem I have is that "last" named range is static, and has been

created manually. If I try to record the macro, it creates a static range.
I need to dynamically assign the current cell (ie: the last cell on the
worksheet) and put it in the named range "last"

Alternately, I would like to dynamically define the name "Database" as the

area of the worksheet that is populated.


Thanks in advance,

Don





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
to change the macros as per active cell and range pol Excel Discussion (Misc queries) 2 August 4th 09 01:19 PM
use active cell to determine range Gizmo Excel Discussion (Misc queries) 2 March 31st 08 04:55 AM
Clearly seeing active cell in a range dsa Excel Discussion (Misc queries) 2 March 24th 08 03:22 PM
need to Copy or Move to active cell from specified range kaream Excel Discussion (Misc queries) 2 December 14th 05 08:12 AM
Setting bkcolor on active cell when left mouse doubleclikked Jan Eikeland Excel Programming 3 December 12th 03 12:45 PM


All times are GMT +1. The time now is 05:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"