ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   newbie help - code need correcting (https://www.excelbanter.com/excel-programming/342421-newbie-help-code-need-correcting.html)

haitch2

newbie help - code need correcting
 

Hi

Im very inexperiance with VBA so please be gental :rolleyes: Im trying
to learn

right i have a small bit of code conected to a macro to hide/show
worksheets when a check box is toggled.

Sub Macro1()

If Worksheets("2").Visible = True Then
Worksheets("2").Visible = False
If Worksheets("3").Visible = True Then
Worksheets("3").Visible = False
Else
Worksheets("2").Visible = True
Worksheets("3").Visible = True
End If

End Sub

It hides the sheets but i cant get them to reapear again.

i can get it to work for one sheet but not 2.

Thanks for any help


--
haitch2
------------------------------------------------------------------------
haitch2's Profile: http://www.excelforum.com/member.php...o&userid=27677
View this thread: http://www.excelforum.com/showthread...hreadid=474940


Vacation's Over

newbie help - code need correcting
 
if sheet number no quotes, if you name sheets on the tab then use quotes

Sub Macro1()
With activeworkbook
If .sheets(2).Visible = True Then
.sheets(2).Visible = False
else
.sheets(2).visible = True
end if

If .sheets(3).Visible = True Then
.sheets(3).Visible = False
else
.sheets(3).visible = True
end if
end With

End Sub

"haitch2" wrote:


Hi

Im very inexperiance with VBA so please be gental :rolleyes: Im trying
to learn

right i have a small bit of code conected to a macro to hide/show
worksheets when a check box is toggled.

Sub Macro1()

If Worksheets("2").Visible = True Then
Worksheets("2").Visible = False
If Worksheets("3").Visible = True Then
Worksheets("3").Visible = False
Else
Worksheets("2").Visible = True
Worksheets("3").Visible = True
End If

End Sub

It hides the sheets but i cant get them to reapear again.

i can get it to work for one sheet but not 2.

Thanks for any help


--
haitch2
------------------------------------------------------------------------
haitch2's Profile: http://www.excelforum.com/member.php...o&userid=27677
View this thread: http://www.excelforum.com/showthread...hreadid=474940



Steve

newbie help - code need correcting
 
Try copying the following code into a new module. Individually run them to
see what they do. to follow the loops, click anywhere within then module and
press F8 to watch the code advance line by line.


Sub ShIndex()
' all sheets are indexed. This gives the index number
For Each sh In Worksheets
MsgBox sh.Index
Next sh
End Sub


Sub ShName()
' This gives the sheet name
For Each sh In Worksheets
MsgBox sh.Name
Next sh
End Sub

Sub Shhide()
' this shows the Visible state of the sheets. -1 = visible 0 = not visible
For Each sh In Worksheets

MsgBox sh.Name & " " & sh.Visible

Next sh

End Sub

Sub ToggleShVisible()

For Each sh In Worksheets
If sh.Index < 1 Then ' You can't hide all sheets so, skip index 1
sh.Visible = Not sh.Visible 'the 'Not' reverses the current
visible setting when used this way
End If
Next sh

End Sub


"haitch2" wrote in
message ...

Hi

Im very inexperiance with VBA so please be gental :rolleyes: Im trying
to learn

right i have a small bit of code conected to a macro to hide/show
worksheets when a check box is toggled.

Sub Macro1()

If Worksheets("2").Visible = True Then
Worksheets("2").Visible = False
If Worksheets("3").Visible = True Then
Worksheets("3").Visible = False
Else
Worksheets("2").Visible = True
Worksheets("3").Visible = True
End If

End Sub

It hides the sheets but i cant get them to reapear again.

i can get it to work for one sheet but not 2.

Thanks for any help


--
haitch2
------------------------------------------------------------------------
haitch2's Profile:
http://www.excelforum.com/member.php...o&userid=27677
View this thread: http://www.excelforum.com/showthread...hreadid=474940




Jim Cone

newbie help - code need correcting
 
h,

Since you are new, you will find the following useful...
http://www.cpearson.com/excel/newposte.htm

Jim Cone
San Francisco, USA


"haitch2" wrote in message
...
Hi
Im very inexperiance with VBA so please be gental :rolleyes: Im trying
to learn
right i have a small bit of code conected to a macro to hide/show
worksheets when a check box is toggled.
Sub Macro1()
If Worksheets("2").Visible = True Then
Worksheets("2").Visible = False
If Worksheets("3").Visible = True Then
Worksheets("3").Visible = False
Else
Worksheets("2").Visible = True
Worksheets("3").Visible = True
End If
End Sub
It hides the sheets but i cant get them to reapear again.
i can get it to work for one sheet but not 2.
Thanks for any help


Ragnar Midtskogen

newbie help - code need correcting
 
Try this

If Worksheets("2").Visible = True Then
Worksheets("2").Visible = False
Else
Worksheets("2").Visible = True
End If
If Worksheets("3").Visible = True Then
Worksheets("3").Visible = False
Else
Worksheets("3").Visible = True
End If

Ragnar




haitch2[_2_]

newbie help - code need correcting
 

Thankyou for all your help, I have now got it to work as is should and i
think i understand were i went wrong, so thats a start.

Sorry to Jim Cone, i have read the the guide line now and will try to
be more specific next time, Thankyou.


--
haitch2
------------------------------------------------------------------------
haitch2's Profile: http://www.excelforum.com/member.php...o&userid=27677
View this thread: http://www.excelforum.com/showthread...hreadid=474940



All times are GMT +1. The time now is 05:43 AM.

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