#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 407
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default 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

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 407
Default 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



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 407
Default 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



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
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



All times are GMT +1. The time now is 02:05 PM.

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"