Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Define a range globally

I have many macros that create separate pivot tables (on separate
sheets) based on the same range (my data source sheet).
I tried defining the range globally but I get errors.
I.E.
In module1:
Public rngRawData as range

Then in the workbook_open event I want to set the range:
Set rngRawData = ActiveWorkbook.Sheets("Data").Range("R1C1:R981C30" )

I get an object-defined or application-defined error.

Can someone please tell me what I'm doing wrong?

Thanks,
Debbie
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Define a range globally

Debbie:

It worked for me if I used A1 notation: Range("$A$1:$AD$981")

You can use
Application.ConvertFormula("R1C1:R981C30", xlR1C1, xlA1)
to convert from R1C1 if necessary.

--
George Nicholson

Remove 'Junk' from return address.

"Debbie" wrote in message
om...
I have many macros that create separate pivot tables (on separate
sheets) based on the same range (my data source sheet).
I tried defining the range globally but I get errors.
I.E.
In module1:
Public rngRawData as range

Then in the workbook_open event I want to set the range:
Set rngRawData = ActiveWorkbook.Sheets("Data").Range("R1C1:R981C30" )

I get an object-defined or application-defined error.

Can someone please tell me what I'm doing wrong?

Thanks,
Debbie



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Define a range globally

Either:
Set rngRawData = ActiveWorkbook.Sheets("Data").Range("A1:AD981")
or:
With ActiveWorkbook.Sheets("data")
Set rngRawData = .Range(.Cells(1, 1), .Cells(981, 30))
End With

worked ok for me.

(the top version worked ok for George, too.)

But my real question is do you want activeworkbook or ThisWorkbook?

If the worksheet data is in the same workbook as the code, then I'd use
ThisWorkbook. (Just in case you ever decide to hide the workbook or make it an
addin--then it won't be the activeworkbook.)


Debbie wrote:

I have many macros that create separate pivot tables (on separate
sheets) based on the same range (my data source sheet).
I tried defining the range globally but I get errors.
I.E.
In module1:
Public rngRawData as range

Then in the workbook_open event I want to set the range:
Set rngRawData = ActiveWorkbook.Sheets("Data").Range("R1C1:R981C30" )

I get an object-defined or application-defined error.

Can someone please tell me what I'm doing wrong?

Thanks,
Debbie


--

Dave Peterson

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
Define Name range Gotroots Excel Discussion (Misc queries) 10 December 19th 09 11:30 AM
Define a range jlclyde Excel Discussion (Misc queries) 2 April 17th 08 08:26 PM
how to define range names anton New Users to Excel 1 October 14th 05 08:28 AM
Define a range based on another named range Basil Excel Worksheet Functions 2 February 21st 05 01:47 PM
Define a Range depending on where the EOF is Dag Johansen[_5_] Excel Programming 5 September 23rd 03 03:45 AM


All times are GMT +1. The time now is 05:30 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"