Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Set a range for all worksheets in workbook??


Is it possible to Set a range so that I can use it on any worksheet in
my workbook?

Currently, I am selecting each sheet and then setting the range. What
I would like to do is set it once and then be able to call it from any
worksheet.

Here is my range code:
Dim rngsort As Range, rngsubtotal As Range

' I then set these ranges below on each sheet I am working on...

Set rngsort = Range(Cells(4, 1), Cells(Rows.Count, 7).End(xlDown))
Set rngsubtotal = Range(Cells(3, 1), Cells(Rows.Count, 7).End(xlDown))

Thanks for any advice offered!!!


--
Celt
------------------------------------------------------------------------
Celt's Profile: http://www.excelforum.com/member.php...o&userid=19413
View this thread: http://www.excelforum.com/showthread...hreadid=551126

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Set a range for all worksheets in workbook??

You can do this even for open workbooks as well as worksheets:

Set r1 = Workbooks("Book1").Worksheets("Sheet1").Cells(1,2)

--
Gary's Student


"Celt" wrote:


Is it possible to Set a range so that I can use it on any worksheet in
my workbook?

Currently, I am selecting each sheet and then setting the range. What
I would like to do is set it once and then be able to call it from any
worksheet.

Here is my range code:
Dim rngsort As Range, rngsubtotal As Range

' I then set these ranges below on each sheet I am working on...

Set rngsort = Range(Cells(4, 1), Cells(Rows.Count, 7).End(xlDown))
Set rngsubtotal = Range(Cells(3, 1), Cells(Rows.Count, 7).End(xlDown))

Thanks for any advice offered!!!


--
Celt
------------------------------------------------------------------------
Celt's Profile: http://www.excelforum.com/member.php...o&userid=19413
View this thread: http://www.excelforum.com/showthread...hreadid=551126


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Set a range for all worksheets in workbook??


Thanks Gary's Student!!

Bear with me here for a sec.....

In the example you provided, since you specified "Sheet1" does tha
mean the range applies only to Sheet1?

Let's say my workbook is called "Fred.xls" and my worksheets are Sheet
- Sheet3.

What would my set range need to look like so that I could use rngsor
or rngsubtotal on every sheet?

Thanks again for your help

--
Cel
-----------------------------------------------------------------------
Celt's Profile: http://www.excelforum.com/member.php...fo&userid=1941
View this thread: http://www.excelforum.com/showthread.php?threadid=55112

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Set a range for all worksheets in workbook??

If you try to do something like:

Sub Macro1()
Dim r As Range
Set r = Range("A1:B2")
r.Select
Sheets("Sheet2").Select
ActiveSheet.r.Select
End Sub

In order to select the same block of cells on Sheet2 that were selected on
Sheet1, the macro fails.


If you want to save the address of a block of cells and select it on various
sheets, the trick is to use a string rather than a range:

Sub Macro1()
Dim r As Range, s As String
s = "A1:B2"
Set r = Range(s)
r.Select
Sheets("Sheet2").Select
ActiveSheet.Range(s).Select
End Sub

the variable s holds the information and can be used on any sheet.

--
Gary's Student


"Celt" wrote:


Thanks Gary's Student!!

Bear with me here for a sec.....

In the example you provided, since you specified "Sheet1" does that
mean the range applies only to Sheet1?

Let's say my workbook is called "Fred.xls" and my worksheets are Sheet1
- Sheet3.

What would my set range need to look like so that I could use rngsort
or rngsubtotal on every sheet?

Thanks again for your help!


--
Celt
------------------------------------------------------------------------
Celt's Profile: http://www.excelforum.com/member.php...o&userid=19413
View this thread: http://www.excelforum.com/showthread...hreadid=551126


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Set a range for all worksheets in workbook??

Dim sh as Worksheet
for each sh in thisWorkbook.Worksheets
with sh
Set rngsort = .Range(.Cells(4, 1), .Cells(Rows.Count, 7).End(xlDown))
Set rngsubtotal = .Range(.Cells(3, 1), .Cells(Rows.Count, 7).End(xlDown))
End With
' now work with rngsort adn rngsubtotal for "sh"
' i.e. finish processing "sh" then move on and do the
' next "sh". Your variables are reset for each "sh"
' as it is processed
Next sh

--
Regards,
Tom Ogilvy




"Celt" wrote:


Thanks Gary's Student!!

Bear with me here for a sec.....

In the example you provided, since you specified "Sheet1" does that
mean the range applies only to Sheet1?

Let's say my workbook is called "Fred.xls" and my worksheets are Sheet1
- Sheet3.

What would my set range need to look like so that I could use rngsort
or rngsubtotal on every sheet?

Thanks again for your help!


--
Celt
------------------------------------------------------------------------
Celt's Profile: http://www.excelforum.com/member.php...o&userid=19413
View this thread: http://www.excelforum.com/showthread...hreadid=551126




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Set a range for all worksheets in workbook??


Thanks very much Tom & Gary's Student!!!

--
Cel
-----------------------------------------------------------------------
Celt's Profile: http://www.excelforum.com/member.php...fo&userid=1941
View this thread: http://www.excelforum.com/showthread.php?threadid=55112

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
using the same range name on different worksheets in a workbook Paul Excel Discussion (Misc queries) 9 May 28th 09 02:07 AM
Combine worksheets in multiple workbook in one workbook with a macro Sam Commar Excel Discussion (Misc queries) 2 April 2nd 09 01:09 PM
Sum same cell/range of multiple worksheets within a workbook... geld Excel Worksheet Functions 3 January 5th 07 05:15 AM
Hide range of worksheets in a workbook AuthorizedUserPF[_2_] Excel Programming 2 April 24th 05 06:58 PM
Link multiple worksheets in one workbook to another workbook and . HeatherCarr Excel Programming 0 March 28th 05 10:35 PM


All times are GMT +1. The time now is 09:15 PM.

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

About Us

"It's about Microsoft Excel"