ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code confusion (https://www.excelbanter.com/excel-programming/383080-code-confusion.html)

JMay

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?




Martin Fishlock

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?






All times are GMT +1. The time now is 03:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com