Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Wes
 
Posts: n/a
Default reference to sheets without using sheet names

Just wondering if there is a way to reference a sheet without using its name.
I know in VBA you can reference the first, second, third etc. sheet or use
their names.

I want to use a formula that references a certain sheet dependent on a
different cell value. For example: if cell a1 value is 3, then my formula
will refernce a cell on the third sheet. if cell a1 is 2, then the formula
would reference the same cell but on the second sheet.

Thanks in advance for your help.
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

Worksheets(Range("A1").Value).Range("somecellref") .Value

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wes" wrote in message
...
Just wondering if there is a way to reference a sheet without using its

name.
I know in VBA you can reference the first, second, third etc. sheet or

use
their names.

I want to use a formula that references a certain sheet dependent on a
different cell value. For example: if cell a1 value is 3, then my formula
will refernce a cell on the third sheet. if cell a1 is 2, then the

formula
would reference the same cell but on the second sheet.

Thanks in advance for your help.



  #3   Report Post  
Wes
 
Posts: n/a
Default

Sorry I guess I didn't word my question clearly. I'm wanting to do this as a
worksheet function. Is that possible? I was hoping to make this spreadsheet
entirely without VBA.

Thanks.

"Bob Phillips" wrote:

Worksheets(Range("A1").Value).Range("somecellref") .Value

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wes" wrote in message
...
Just wondering if there is a way to reference a sheet without using its

name.
I know in VBA you can reference the first, second, third etc. sheet or

use
their names.

I want to use a formula that references a certain sheet dependent on a
different cell value. For example: if cell a1 value is 3, then my formula
will refernce a cell on the third sheet. if cell a1 is 2, then the

formula
would reference the same cell but on the second sheet.

Thanks in advance for your help.




  #4   Report Post  
Bob Phillips
 
Posts: n/a
Default

No as easily.

You could use

=INDIRECT("Sheet"&A1&"!C5")

as an example, as long as they all follow the Sheet1, Sheet2, ... format.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wes" wrote in message
...
Sorry I guess I didn't word my question clearly. I'm wanting to do this

as a
worksheet function. Is that possible? I was hoping to make this

spreadsheet
entirely without VBA.

Thanks.

"Bob Phillips" wrote:

Worksheets(Range("A1").Value).Range("somecellref") .Value

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wes" wrote in message
...
Just wondering if there is a way to reference a sheet without using

its
name.
I know in VBA you can reference the first, second, third etc. sheet

or
use
their names.

I want to use a formula that references a certain sheet dependent on a
different cell value. For example: if cell a1 value is 3, then my

formula
will refernce a cell on the third sheet. if cell a1 is 2, then the

formula
would reference the same cell but on the second sheet.

Thanks in advance for your help.






  #5   Report Post  
Wes
 
Posts: n/a
Default

To bad there isn't an easy solution, since the problem I have is that they
all have sheet names that have been changed, and may change again. That is
what led me to this problem in the first place.

Thanks for your help though.

"Bob Phillips" wrote:

No as easily.

You could use

=INDIRECT("Sheet"&A1&"!C5")

as an example, as long as they all follow the Sheet1, Sheet2, ... format.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wes" wrote in message
...
Sorry I guess I didn't word my question clearly. I'm wanting to do this

as a
worksheet function. Is that possible? I was hoping to make this

spreadsheet
entirely without VBA.

Thanks.

"Bob Phillips" wrote:

Worksheets(Range("A1").Value).Range("somecellref") .Value

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wes" wrote in message
...
Just wondering if there is a way to reference a sheet without using

its
name.
I know in VBA you can reference the first, second, third etc. sheet

or
use
their names.

I want to use a formula that references a certain sheet dependent on a
different cell value. For example: if cell a1 value is 3, then my

formula
will refernce a cell on the third sheet. if cell a1 is 2, then the
formula
would reference the same cell but on the second sheet.

Thanks in advance for your help.








  #6   Report Post  
Duke Carey
 
Posts: n/a
Default

You could have a table that lists the sheet number in one column & the sheet
name in the other, then use a VLOOKUP() to supply the sheet name to Bob's
INDIRECT() function. All you'd have to do then is maintain the table of
sheet names


"Wes" wrote:

To bad there isn't an easy solution, since the problem I have is that they
all have sheet names that have been changed, and may change again. That is
what led me to this problem in the first place.

Thanks for your help though.

"Bob Phillips" wrote:

No as easily.

You could use

=INDIRECT("Sheet"&A1&"!C5")

as an example, as long as they all follow the Sheet1, Sheet2, ... format.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wes" wrote in message
...
Sorry I guess I didn't word my question clearly. I'm wanting to do this

as a
worksheet function. Is that possible? I was hoping to make this

spreadsheet
entirely without VBA.

Thanks.

"Bob Phillips" wrote:

Worksheets(Range("A1").Value).Range("somecellref") .Value

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Wes" wrote in message
...
Just wondering if there is a way to reference a sheet without using

its
name.
I know in VBA you can reference the first, second, third etc. sheet

or
use
their names.

I want to use a formula that references a certain sheet dependent on a
different cell value. For example: if cell a1 value is 3, then my

formula
will refernce a cell on the third sheet. if cell a1 is 2, then the
formula
would reference the same cell but on the second sheet.

Thanks in advance for your help.






  #7   Report Post  
Harlan Grove
 
Posts: n/a
Default

Bob Phillips wrote...
No as easily.

You could use

=INDIRECT("Sheet"&A1&"!C5")

as an example, as long as they all follow the Sheet1, Sheet2, ... format.

....

Another option would be user-defined functions, e.g.,


Function ref(wsr As Variant, rr As String) As Range
Dim wb As Workbook, ws As Worksheet

Set wb = Application.Caller.Parent.Parent

If TypeOf wsr Is Range Then wsr = wsr.Cells(1, 1).Value2

If VarType(wsr) = vbDouble Then
wsr = Int(wsr)

If 1 <= wsr And wsr <= wb.Worksheets.Count Then
Set ref = wb.Worksheets(wsr).Range(rr)
End If

ElseIf VarType(wsr) = vbString Then
On Error Resume Next
Set ws = Evaluate("'" & wsr & "'!A1").Parent

If Not ws Is Nothing Then
Set ref = ws.Range(rr)

Else
Err.Clear

For Each ws In wb.Worksheets
If ws.CodeName = wsr Then Set ref = ws.Range(rr)
Next ws

End If

End If

End Function


Off on a tangent: I was testing this udf with the formula

A2:
=CELL("Address",ref(A1,"A5"))

in a new workbook. I'd just like to point out that CELL called with 1st
arg "Address" and second arg referring to a cell in a different
worksheet happily includes the name of the unsaved workbook, but called
with 1st argument "Filename" it returns "". Obviously it isn't
impossible to return the dummy filename for unsaved files.

Microsoft copied Lotus 123 Release 2's @CELL as the basis for Excel's
CELL function. Since 123 Release 3.0 (Summer 1989), 123's @CELL
function returns a dummy but nonblank workbook name when called with
"Filename" as 1st arg. I know it's imprudent to expect Microsoft to
bring bits & pieces of Excel up to the level of functionality that its
erstwhile competitors achieved more than a decade and half ago, but
it's still nice to dream about. And with no effective competition
anymore, ridicule is the only means left to influence Microsoft.

  #8   Report Post  
Wes
 
Posts: n/a
Default

Thanks Harlan, but unfortunately I'm trying hard to do this without any VBA.
Having coding in this spreadsheet becomes a pain because it is used throught
a school on many different computers which I would then have to lower
security to and then install a certificate on.



"Harlan Grove" wrote:

Bob Phillips wrote...
No as easily.

You could use

=INDIRECT("Sheet"&A1&"!C5")

as an example, as long as they all follow the Sheet1, Sheet2, ... format.

....

Another option would be user-defined functions, e.g.,


Function ref(wsr As Variant, rr As String) As Range
Dim wb As Workbook, ws As Worksheet

Set wb = Application.Caller.Parent.Parent

If TypeOf wsr Is Range Then wsr = wsr.Cells(1, 1).Value2

If VarType(wsr) = vbDouble Then
wsr = Int(wsr)

If 1 <= wsr And wsr <= wb.Worksheets.Count Then
Set ref = wb.Worksheets(wsr).Range(rr)
End If

ElseIf VarType(wsr) = vbString Then
On Error Resume Next
Set ws = Evaluate("'" & wsr & "'!A1").Parent

If Not ws Is Nothing Then
Set ref = ws.Range(rr)

Else
Err.Clear

For Each ws In wb.Worksheets
If ws.CodeName = wsr Then Set ref = ws.Range(rr)
Next ws

End If

End If

End Function


Off on a tangent: I was testing this udf with the formula

A2:
=CELL("Address",ref(A1,"A5"))

in a new workbook. I'd just like to point out that CELL called with 1st
arg "Address" and second arg referring to a cell in a different
worksheet happily includes the name of the unsaved workbook, but called
with 1st argument "Filename" it returns "". Obviously it isn't
impossible to return the dummy filename for unsaved files.

Microsoft copied Lotus 123 Release 2's @CELL as the basis for Excel's
CELL function. Since 123 Release 3.0 (Summer 1989), 123's @CELL
function returns a dummy but nonblank workbook name when called with
"Filename" as 1st arg. I know it's imprudent to expect Microsoft to
bring bits & pieces of Excel up to the level of functionality that its
erstwhile competitors achieved more than a decade and half ago, but
it's still nice to dream about. And with no effective competition
anymore, ridicule is the only means left to influence Microsoft.


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 a relative SHEET reference for source data in a chart James Charts and Charting in Excel 6 August 16th 05 05:07 PM
Formula checking multiple worksheets sonic-the-mouse Excel Worksheet Functions 2 June 5th 05 07:48 PM
Formula checking multiple worksheets sonic-the-mouse Excel Worksheet Functions 2 June 5th 05 03:28 AM
calculate totals of 5 sheets on to 6th sheet. salvo Excel Worksheet Functions 1 March 25th 05 06:58 AM
Printing separate sheets on one paper sheet Attyla Excel Discussion (Misc queries) 2 December 19th 04 05:58 PM


All times are GMT +1. The time now is 05:30 AM.

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"