Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro for calling the previous worksheet

I've been using the function below that I found in another post. However, I
am having a problem that if I have another workbook open at the same time,
then it sometimes grabs data from Sheets(n-1) from that workbook. I added
Application.Volatile to the function to have the function get the new data as
soon as the pointed to cell changes. Could this be what is causing the
workbook confusion?

Function PrevSheet(rg As Range)
n = Application.Caller.Parent.Index
If n = 1 Then
PrevSheet = CVErr(xlErrRef)
ElseIf TypeName(Sheets(n - 1)) = "Chart" Then
PrevSheet = CVErr(xlErrNA)
Else
PrevSheet = Sheets(n - 1).Range(rg.Address).Value
End If
End Function



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Macro for calling the previous worksheet

Try

Function PrevSheet(rg As Range)
With Application.Caller.Parent

n = .Index
If n = 1 Then
PrevSheet = CVErr(xlErrRef)
ElseIf TypeName(.Parent.Sheets(n - 1)) = "Chart" Then
PrevSheet = CVErr(xlErrNA)
Else
PrevSheet = .Parent.Sheets(n - 1).Range(rg.Address).Value
End If
End With
End Function


--
__________________________________
HTH

Bob

"Balkar" wrote in message
...
I've been using the function below that I found in another post. However,
I
am having a problem that if I have another workbook open at the same time,
then it sometimes grabs data from Sheets(n-1) from that workbook. I added
Application.Volatile to the function to have the function get the new data
as
soon as the pointed to cell changes. Could this be what is causing the
workbook confusion?

Function PrevSheet(rg As Range)
n = Application.Caller.Parent.Index
If n = 1 Then
PrevSheet = CVErr(xlErrRef)
ElseIf TypeName(Sheets(n - 1)) = "Chart" Then
PrevSheet = CVErr(xlErrNA)
Else
PrevSheet = Sheets(n - 1).Range(rg.Address).Value
End If
End Function





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro for calling the previous worksheet

So far it looks good. Why would Application.Caller.Parent.Parent.Sheet...
work better than Application.Caller.Parent..Sheet...?

"Bob Phillips" wrote:

Try

Function PrevSheet(rg As Range)
With Application.Caller.Parent

n = .Index
If n = 1 Then
PrevSheet = CVErr(xlErrRef)
ElseIf TypeName(.Parent.Sheets(n - 1)) = "Chart" Then
PrevSheet = CVErr(xlErrNA)
Else
PrevSheet = .Parent.Sheets(n - 1).Range(rg.Address).Value
End If
End With
End Function


--
__________________________________
HTH

Bob

"Balkar" wrote in message
...
I've been using the function below that I found in another post. However,
I
am having a problem that if I have another workbook open at the same time,
then it sometimes grabs data from Sheets(n-1) from that workbook. I added
Application.Volatile to the function to have the function get the new data
as
soon as the pointed to cell changes. Could this be what is causing the
workbook confusion?

Function PrevSheet(rg As Range)
n = Application.Caller.Parent.Index
If n = 1 Then
PrevSheet = CVErr(xlErrRef)
ElseIf TypeName(Sheets(n - 1)) = "Chart" Then
PrevSheet = CVErr(xlErrNA)
Else
PrevSheet = Sheets(n - 1).Range(rg.Address).Value
End If
End Function






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Macro for calling the previous worksheet

Because the parent is the sheet, so you have to go up one to the
parent.parent, the book, which has sheet properties.

--
__________________________________
HTH

Bob

"Balkar" wrote in message
...
So far it looks good. Why would Application.Caller.Parent.Parent.Sheet...
work better than Application.Caller.Parent..Sheet...?

"Bob Phillips" wrote:

Try

Function PrevSheet(rg As Range)
With Application.Caller.Parent

n = .Index
If n = 1 Then
PrevSheet = CVErr(xlErrRef)
ElseIf TypeName(.Parent.Sheets(n - 1)) = "Chart" Then
PrevSheet = CVErr(xlErrNA)
Else
PrevSheet = .Parent.Sheets(n - 1).Range(rg.Address).Value
End If
End With
End Function


--
__________________________________
HTH

Bob

"Balkar" wrote in message
...
I've been using the function below that I found in another post.
However,
I
am having a problem that if I have another workbook open at the same
time,
then it sometimes grabs data from Sheets(n-1) from that workbook. I
added
Application.Volatile to the function to have the function get the new
data
as
soon as the pointed to cell changes. Could this be what is causing the
workbook confusion?

Function PrevSheet(rg As Range)
n = Application.Caller.Parent.Index
If n = 1 Then
PrevSheet = CVErr(xlErrRef)
ElseIf TypeName(Sheets(n - 1)) = "Chart" Then
PrevSheet = CVErr(xlErrNA)
Else
PrevSheet = Sheets(n - 1).Range(rg.Address).Value
End If
End Function







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
Calling a macro from Worksheet--Activate Fatz Excel Discussion (Misc queries) 3 March 5th 08 11:07 PM
calling/running a macro on another worksheet Sunny Excel Programming 2 April 10th 07 04:40 PM
calling worksheet function from a macro Joe Farruggio Excel Worksheet Functions 3 November 20th 06 10:01 PM
Calling a macro in another worksheet Tolga[_2_] Excel Programming 2 August 5th 04 07:03 PM
Macro to return to previous worksheet gurs Excel Programming 6 October 17th 03 05:09 PM


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