ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   If Then (https://www.excelbanter.com/excel-programming/373697-if-then.html)

Dean[_8_]

If Then
 
Can someone give me the exact code for the following general situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or sheet3, then hide row 16. Or, if sheet 4, hide row 18. If any other sheet, don't hide anything - that I suppose requires no text!

Thanks!
Dean

Stefi

If Then
 
Sub test()
If ActiveSheet.Name = "Sheet1" Or ActiveSheet.Name = "Sheet2" Or
ActiveSheet.Name = "Sheet3" Then
Rows("16").EntireRow.Hidden = True
ElseIf ActiveSheet.Name = "Sheet4" Then
Rows("18").EntireRow.Hidden = True
End If
End Sub

Regards,
Stefi


€˛Dean€¯ ezt Ć*rta:

Can someone give me the exact code for the following general situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or sheet3, then hide row 16. Or, if sheet 4, hide row 18. If any other sheet, don't hide anything - that I suppose requires no text!

Thanks!
Dean


Jim May

If Then
 
Dean I concocked this; test it out completely.. (it worked for me)..

Sub test()
Dim arr As Variant
Dim arr1 As Variant
Dim arrcount As Integer
arr = Array("Sheet1", "Sheet2", "Sheet3")
arr1 = "Sheet4"
arrcount = UBound(arr)
For i = 1 To arrcount
If arr(i) = ActiveSheet.Name Then
Range("A16").EntireRow.Hidden = True
End If
Next i
If arr1 = ActiveSheet.Name Then
Range("A18").EntireRow.Hidden = True
End If
End Sub

HTH
Jim May


"Dean" wrote in message
:

Can someone give me the exact code for the following general situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or sheet3, then hide row 16. Or, if sheet 4, hide row 18. If any other sheet, don't hide anything - that I suppose requires no text!

Thanks!
Dean



Tom Ogilvy

If Then
 
select Case Activesheet.Name
Case "Sheet1", "Sheet2", "Sheet3"
rows(16).Hidden = True
Case "Sheet4"
rows(18).Hidden = True
End Select

would be another way.

--
Regards,
Tom Ogilvy


"Dean" wrote:

Can someone give me the exact code for the following general situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or sheet3, then hide row 16. Or, if sheet 4, hide row 18. If any other sheet, don't hide anything - that I suppose requires no text!

Thanks!
Dean


Dave Peterson

If Then
 
Sometimes using the "select case" syntax makes things easier to see.

Option Explicit
Sub testme()
With ActiveSheet
Select Case LCase(.Name)
Case Is = "sheet1", "sheet2", "sheet3"
.Rows(16).Hidden = True
Case Is = "sheet4"
.Rows(4).Hidden = True
Case Else
'do nothing
End Select
End With
End Sub

ps. this is a text only newsgroup--please post in plain text (not HTML and no
attachments).

Dean wrote:

Can someone give me the exact code for the following general situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or sheet3,
then hide row 16. Or, if sheet 4, hide row 18. If any other sheet, don't
hide anything - that I suppose requires no text!

Thanks!
Dean


--

Dave Peterson

Stefi

If Then
 
That's a nice code!
Stefi


€˛Tom Ogilvy€¯ ezt Ć*rta:

select Case Activesheet.Name
Case "Sheet1", "Sheet2", "Sheet3"
rows(16).Hidden = True
Case "Sheet4"
rows(18).Hidden = True
End Select

would be another way.

--
Regards,
Tom Ogilvy


"Dean" wrote:

Can someone give me the exact code for the following general situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or sheet3, then hide row 16. Or, if sheet 4, hide row 18. If any other sheet, don't hide anything - that I suppose requires no text!

Thanks!
Dean


Dean[_8_]

If Then
 
Wow, what a response!

Dave, I'm not sure what your point was, seemingly praising Tom's approach
but still offering a slightly different macro. How is yours different from
Tom's? Are you just pointing out that it is case sensitive, so the lcase (I
assume that's lower case) is safer?

In any event, I thank everyone, as it looks like any of these will do the
trick.

Dean


"Dave Peterson" wrote in message
...
Sometimes using the "select case" syntax makes things easier to see.

Option Explicit
Sub testme()
With ActiveSheet
Select Case LCase(.Name)
Case Is = "sheet1", "sheet2", "sheet3"
.Rows(16).Hidden = True
Case Is = "sheet4"
.Rows(4).Hidden = True
Case Else
'do nothing
End Select
End With
End Sub

ps. this is a text only newsgroup--please post in plain text (not HTML
and no
attachments).

Dean wrote:

Can someone give me the exact code for the following general situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or
sheet3,
then hide row 16. Or, if sheet 4, hide row 18. If any other sheet,
don't
hide anything - that I suppose requires no text!

Thanks!
Dean


--

Dave Peterson




Dave Peterson

If Then
 
When I retrieved the headers in this newsgroup, Tom's response wasn't there yet.



Dean wrote:

Wow, what a response!

Dave, I'm not sure what your point was, seemingly praising Tom's approach
but still offering a slightly different macro. How is yours different from
Tom's? Are you just pointing out that it is case sensitive, so the lcase (I
assume that's lower case) is safer?

In any event, I thank everyone, as it looks like any of these will do the
trick.

Dean

"Dave Peterson" wrote in message
...
Sometimes using the "select case" syntax makes things easier to see.

Option Explicit
Sub testme()
With ActiveSheet
Select Case LCase(.Name)
Case Is = "sheet1", "sheet2", "sheet3"
.Rows(16).Hidden = True
Case Is = "sheet4"
.Rows(4).Hidden = True
Case Else
'do nothing
End Select
End With
End Sub

ps. this is a text only newsgroup--please post in plain text (not HTML
and no
attachments).

Dean wrote:

Can someone give me the exact code for the following general situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or
sheet3,
then hide row 16. Or, if sheet 4, hide row 18. If any other sheet,
don't
hide anything - that I suppose requires no text!

Thanks!
Dean


--

Dave Peterson


--

Dave Peterson

Dean[_8_]

If Then
 
Possibly your problem is like mine: I have noticed that, when using Outlook
Express, only recently, if the title of my post is the same as any other one
that has ever been posted to this newsgroup(!), it gets included underneath
the old original post by someone else, which makes it difficult to find,
even when OE is set to just show replies to my messages. I guess I need to
start using very unique titles. I don't recall that this was the case ever
before (perhaps I somehow changed an OE setting).

Thanks!
Dean

"Dave Peterson" wrote in message
...
When I retrieved the headers in this newsgroup, Tom's response wasn't
there yet.



Dean wrote:

Wow, what a response!

Dave, I'm not sure what your point was, seemingly praising Tom's approach
but still offering a slightly different macro. How is yours different
from
Tom's? Are you just pointing out that it is case sensitive, so the lcase
(I
assume that's lower case) is safer?

In any event, I thank everyone, as it looks like any of these will do the
trick.

Dean

"Dave Peterson" wrote in message
...
Sometimes using the "select case" syntax makes things easier to see.

Option Explicit
Sub testme()
With ActiveSheet
Select Case LCase(.Name)
Case Is = "sheet1", "sheet2", "sheet3"
.Rows(16).Hidden = True
Case Is = "sheet4"
.Rows(4).Hidden = True
Case Else
'do nothing
End Select
End With
End Sub

ps. this is a text only newsgroup--please post in plain text (not HTML
and no
attachments).

Dean wrote:

Can someone give me the exact code for the following general
situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or
sheet3,
then hide row 16. Or, if sheet 4, hide row 18. If any other sheet,
don't
hide anything - that I suppose requires no text!

Thanks!
Dean

--

Dave Peterson


--

Dave Peterson




Dave Peterson

If Then
 
I use an early version of Netscape Messenger for my newsreader. For me it was
just a timing issue.

Dean wrote:

Possibly your problem is like mine: I have noticed that, when using Outlook
Express, only recently, if the title of my post is the same as any other one
that has ever been posted to this newsgroup(!), it gets included underneath
the old original post by someone else, which makes it difficult to find,
even when OE is set to just show replies to my messages. I guess I need to
start using very unique titles. I don't recall that this was the case ever
before (perhaps I somehow changed an OE setting).

Thanks!
Dean

"Dave Peterson" wrote in message
...
When I retrieved the headers in this newsgroup, Tom's response wasn't
there yet.



Dean wrote:

Wow, what a response!

Dave, I'm not sure what your point was, seemingly praising Tom's approach
but still offering a slightly different macro. How is yours different
from
Tom's? Are you just pointing out that it is case sensitive, so the lcase
(I
assume that's lower case) is safer?

In any event, I thank everyone, as it looks like any of these will do the
trick.

Dean

"Dave Peterson" wrote in message
...
Sometimes using the "select case" syntax makes things easier to see.

Option Explicit
Sub testme()
With ActiveSheet
Select Case LCase(.Name)
Case Is = "sheet1", "sheet2", "sheet3"
.Rows(16).Hidden = True
Case Is = "sheet4"
.Rows(4).Hidden = True
Case Else
'do nothing
End Select
End With
End Sub

ps. this is a text only newsgroup--please post in plain text (not HTML
and no
attachments).

Dean wrote:

Can someone give me the exact code for the following general
situation:

If the active worksheet when a macro is called is sheet 1 or sheet2 or
sheet3,
then hide row 16. Or, if sheet 4, hide row 18. If any other sheet,
don't
hide anything - that I suppose requires no text!

Thanks!
Dean

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 01:52 AM.

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