Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default Code confusion

On a particular WS I have to custom views set up. I want to put a
button
on the sheet to Toggle between the 2 views.
Off google I found the below (from Chip Pearson):

Sub ToggleViews()
Static ViewName As String
If ViewName = "View1" Then
ThisWorkbook.CustomViews("View2").Show
ViewName = "View2"
Else
ThisWorkbook.CustomViews("View1").Show
ViewName = "View1"
End If
End Sub

I substituted as follows:

Sub ToggleViews()
Static ViewName As String
If ViewName = "Monthly Budget" Then
ThisWorkbook.CustomViews("Compare Budget To Actual").Show
ViewName = "Compare Budget To Actual"
Else
ThisWorkbook.CustomViews("Monthly Budget").Show
ViewName = "Monthly Budget"
End If
End Sub

My revised code is not working - as a matter of fact when I step
thru it using the F8 Key - as I begin the sheet is currently in the
"Monthly Budget" View.. Perhaps because ViewName is undefined my
cursor jumps to the Else line and then the line following. As soon
as I F8 on this line - the code jumps to an unrelated UDF Function
Higher up in the Standard module:
Function FilterCriteria(Rng As Range) As String
'By Stephen Bullen

What's going on here? My Sub toggleViews I have in a standard module,
right?



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Code confusion

Hi,

The code worked fine for me.

Please check your views and the names.

That is were it is probably breaking down.
--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"JMay" wrote:

On a particular WS I have to custom views set up. I want to put a
button
on the sheet to Toggle between the 2 views.
Off google I found the below (from Chip Pearson):

Sub ToggleViews()
Static ViewName As String
If ViewName = "View1" Then
ThisWorkbook.CustomViews("View2").Show
ViewName = "View2"
Else
ThisWorkbook.CustomViews("View1").Show
ViewName = "View1"
End If
End Sub

I substituted as follows:

Sub ToggleViews()
Static ViewName As String
If ViewName = "Monthly Budget" Then
ThisWorkbook.CustomViews("Compare Budget To Actual").Show
ViewName = "Compare Budget To Actual"
Else
ThisWorkbook.CustomViews("Monthly Budget").Show
ViewName = "Monthly Budget"
End If
End Sub

My revised code is not working - as a matter of fact when I step
thru it using the F8 Key - as I begin the sheet is currently in the
"Monthly Budget" View.. Perhaps because ViewName is undefined my
cursor jumps to the Else line and then the line following. As soon
as I F8 on this line - the code jumps to an unrelated UDF Function
Higher up in the Standard module:
Function FilterCriteria(Rng As Range) As String
'By Stephen Bullen

What's going on here? My Sub toggleViews I have in a standard module,
right?




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
Sort confusion ramona Excel Discussion (Misc queries) 2 June 3rd 09 06:25 PM
MDI Confusion CMoya Excel Discussion (Misc queries) 1 February 21st 08 02:11 PM
if statement confusion CV Excel Discussion (Misc queries) 10 October 21st 07 08:55 PM
Command Code Confusion apollo8359 Excel Programming 1 May 13th 06 01:02 AM
Confusion..... Eric @ CMN, Evansville Excel Discussion (Misc queries) 2 December 27th 05 07:15 PM


All times are GMT +1. The time now is 07:20 AM.

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"