Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Return position of a sheet in a workbook

I am using Office 2003 on Windows XP.

I need a function that would return an integer or a long that indicates the
current position of the active sheet, counting the sheets from left to right.

So if you have sheets named: RawData, Reports, Data, and Calcs in a workbook
and "Data" is currently the active sheet, the function should return 3.

Your example code would be most appreciated. Thanks much in advance.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Return position of a sheet in a workbook

The following code just picks up the name of the current worksheet and its
index number (its position) and displayes a message box displaying that
information:

Sub WhereAmI()

Dim wb As Workbook
Dim ws As Worksheet

Set wb = ActiveWorkbook
Set ws = ActiveSheet

MsgBox "The active sheet name is " & ws.Name & _
" and its position is " & ws.Index

Set wb = Nothing
Set ws = Nothing

End Sub

--
Kevin Backmann


"XP" wrote:

I am using Office 2003 on Windows XP.

I need a function that would return an integer or a long that indicates the
current position of the active sheet, counting the sheets from left to right.

So if you have sheets named: RawData, Reports, Data, and Calcs in a workbook
and "Data" is currently the active sheet, the function should return 3.

Your example code would be most appreciated. Thanks much in advance.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Return position of a sheet in a workbook

Just a heads up that this will work if all the sheets to the left are
worksheets. If you insert a chart sheet as the first sheet, for example, it
will give you the wrong number.

Probably not a problem in your example, but something you should be aware
of.

--
Regards,
Tom Ogilvy

"Don Guillett" wrote in message
...
try

Sub sheetlocation()
MsgBox ActiveSheet.Index
End Sub

--
Don Guillett
SalesAid Software

"XP" wrote in message
...
I am using Office 2003 on Windows XP.

I need a function that would return an integer or a long that indicates
the
current position of the active sheet, counting the sheets from left to
right.

So if you have sheets named: RawData, Reports, Data, and Calcs in a
workbook
and "Data" is currently the active sheet, the function should return 3.

Your example code would be most appreciated. Thanks much in advance.





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,316
Default Return position of a sheet in a workbook

Here's a function that returns the index

Function CurrentLocation() As Integer

CurrentLocation = ActiveWorkbook.ActiveSheet.Index

End Function

--
Kevin Backmann


"XP" wrote:

I am using Office 2003 on Windows XP.

I need a function that would return an integer or a long that indicates the
current position of the active sheet, counting the sheets from left to right.

So if you have sheets named: RawData, Reports, Data, and Calcs in a workbook
and "Data" is currently the active sheet, the function should return 3.

Your example code would be most appreciated. Thanks much in advance.

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
function to return position in a list Bill Excel Worksheet Functions 2 March 7th 08 10:01 PM
How to return multiple cells from a data sheet in a seperate workbook [email protected] Excel Worksheet Functions 19 June 27th 07 10:27 PM
Return position for each matching value in entire workbook? Squidman Excel Worksheet Functions 1 September 15th 06 11:36 PM
Formula to return cell position AJPendragon Excel Worksheet Functions 1 February 6th 06 09:34 PM
Return Sheet Names from Closed Workbook crispbd[_38_] Excel Programming 1 November 24th 04 05:46 PM


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