Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sort confusion | Excel Discussion (Misc queries) | |||
MDI Confusion | Excel Discussion (Misc queries) | |||
if statement confusion | Excel Discussion (Misc queries) | |||
Command Code Confusion | Excel Programming | |||
Confusion..... | Excel Discussion (Misc queries) |