Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Loop to skip some sheets in workbook


What do I put where it says 'DO NOTHING so the loop will skip ws. X, Y & Z?

Thanks,
Howard

Option Explicit

Sub LoopThroughSheets()
Dim ws As Worksheet
If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then
'DO NOTHING
Else
'Do some code stuff here like:
ws.Range("B1") = ws.Name
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Loop to skip some sheets in workbook

Hi Howard,

Am Wed, 22 May 2013 23:24:34 -0700 (PDT) schrieb Howard:

What do I put where it says 'DO NOTHING so the loop will skip ws. X, Y & Z?


Sub LoopThroughSheets()
Dim ws As Worksheet
If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then
Else
'Do some code stuff here like:
ws.Range("B1") = ws.Name
End If
End Sub

or:

Sub LoopThroughSheets()
Dim ws As Worksheet
If ws.Name < "X" Or ws.Name < "Y" Or ws.Name < "Z" Then
''Do some code stuff here like:
ws.Range("B1") = ws.Name
End If
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Loop to skip some sheets in workbook

On Thursday, May 23, 2013 1:08:18 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Wed, 22 May 2013 23:24:34 -0700 (PDT) schrieb Howard:



What do I put where it says 'DO NOTHING so the loop will skip ws. X, Y & Z?




Sub LoopThroughSheets()

Dim ws As Worksheet

If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then

Else

'Do some code stuff here like:

ws.Range("B1") = ws.Name

End If

End Sub



or:



Sub LoopThroughSheets()

Dim ws As Worksheet

If ws.Name < "X" Or ws.Name < "Y" Or ws.Name < "Z" Then

''Do some code stuff here like:

ws.Range("B1") = ws.Name

End If

End Sub





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


Thanks, Claus. As always you make it look so easy.

Regards,
Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Loop to skip some sheets in workbook



Thanks, Claus. As always you make it look so easy.



Regards,

Howard


Spoke too soon.

Errors with Object variable or with block variable not set.

Howard
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Loop to skip some sheets in workbook

Hi Howard,

Am Thu, 23 May 2013 01:33:04 -0700 (PDT) schrieb Howard:

Errors with Object variable or with block variable not set.


the loop is missing:

Sub LoopThroughSheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then
Else
'Do some code stuff here like:
ws.Range("B1") = ws.Name
End If
Next
End Sub

Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Loop to skip some sheets in workbook

On Thursday, May 23, 2013 1:37:23 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Thu, 23 May 2013 01:33:04 -0700 (PDT) schrieb Howard:



Errors with Object variable or with block variable not set.




the loop is missing:



Sub LoopThroughSheets()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then

Else

'Do some code stuff here like:

ws.Range("B1") = ws.Name

End If

Next

End Sub



Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


I was looking right it and never saw that, it's a bit late but really my bad.

Thanks Claus.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Loop to skip some sheets in workbook

Claus Busch wrote:
Hi Howard,

Am Wed, 22 May 2013 23:24:34 -0700 (PDT) schrieb Howard:

What do I put where it says 'DO NOTHING so the loop will skip ws. X, Y & Z?


Sub LoopThroughSheets()
Dim ws As Worksheet
If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then
Else
'Do some code stuff here like:
ws.Range("B1") = ws.Name
End If
End Sub

or:

Sub LoopThroughSheets()
Dim ws As Worksheet
If ws.Name < "X" Or ws.Name < "Y" Or ws.Name < "Z" Then
''Do some code stuff here like:
ws.Range("B1") = ws.Name
End If
End Sub


Regards
Claus Busch



AND not OR


If ws.Name < "X" AND ws.Name < "Y" AND ws.Name < "Z"

De Morgan's law

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Loop to skip some sheets in workbook

On Thursday, May 23, 2013 4:36:05 AM UTC-7, witek wrote:
Claus Busch wrote:

Hi Howard,




Am Wed, 22 May 2013 23:24:34 -0700 (PDT) schrieb Howard:




What do I put where it says 'DO NOTHING so the loop will skip ws. X, Y & Z?




Sub LoopThroughSheets()


Dim ws As Worksheet


If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then


Else


'Do some code stuff here like:


ws.Range("B1") = ws.Name


End If


End Sub




or:




Sub LoopThroughSheets()


Dim ws As Worksheet


If ws.Name < "X" Or ws.Name < "Y" Or ws.Name < "Z" Then


''Do some code stuff here like:


ws.Range("B1") = ws.Name


End If


End Sub






Regards


Claus Busch








AND not OR





If ws.Name < "X" AND ws.Name < "Y" AND ws.Name < "Z"



De Morgan's law


Thanks, witek, brings the second code around quite nicely.

Regards,
Howard
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Loop to skip some sheets in workbook

"witek" skrev i melding
...
If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then


AND not OR

If ws.Name < "X" AND ws.Name < "Y" AND ws.Name < "Z"


No. A ws can not have three names at the same time so that test will always
fail.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Loop to skip some sheets in workbook

Harald Staff wrote:
"witek" skrev i melding
...
If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then


AND not OR

If ws.Name < "X" AND ws.Name < "Y" AND ws.Name < "Z"


No. A ws can not have three names at the same time so that test will always
fail.




Have you read de Morgan's law ?


  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 147
Default Loop to skip some sheets in workbook

Harald Staff wrote:
"witek" skrev i melding
...
If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then


AND not OR

If ws.Name < "X" AND ws.Name < "Y" AND ws.Name < "Z"


No. A ws can not have three names at the same time so that test will always
fail.




try what is value of ws.Name < "X" AND ws.Name < "Y" AND ws.Name <
"Z" if ws.Name = "T" .

Is that really false?

please believe me. It is correct.


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Loop to skip some sheets in workbook


try what is value of ws.Name < "X" AND ws.Name < "Y" AND ws.Name <

"Z" if ws.Name = "T" .



Is that really false?



please believe me. It is correct.



I have zero expertise to discuss de Morgan's law, these two macros work on my workbook which has Sheet1, Sheet2, Sheet3, three sheets named X, Y, Z (not SheetX, SheetY, SheetZ)and Sheet4. In that order. The macros are in Sheet1 module.

Option Explicit

Sub LoopThroughSheets()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then
Else
'Do your code stuff here like:
With ws.Cells
With .Font
.ColorIndex = 3
.Bold = False
.Italic = False
.Underline = False
.Name = "Arial"
.Size = 12
End With
End With
End If

Next
End Sub

Sub LoopThroughSheetsXX()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets

If ws.Name < "X" And ws.Name < "Y" And ws.Name < "Z" Then
ws.Range("C5") = ws.Name
With ws.Cells
With .Font
.ColorIndex = 0
.Bold = True
.Italic = True
.Underline = True
.Name = "Arial"
.Size = 12
End With
End With
End If
Next

End Sub

Regards,
Howard
  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Loop to skip some sheets in workbook

"witek" skrev i melding
...
Harald Staff wrote:
"witek" skrev i melding
...
If ws.Name = "X" Or ws.Name = "Y" Or ws.Name = "Z" Then

AND not OR

If ws.Name < "X" AND ws.Name < "Y" AND ws.Name < "Z"


No. A ws can not have three names at the same time so that test will
always
fail.


try what is value of ws.Name < "X" AND ws.Name < "Y" AND ws.Name < "Z"
if ws.Name = "T" .


Sorry, you're right. It stated "AND not OR", but not "< not =" , so I
misread it. But it leaves the question why this? Does it perform better than
the original, or than a Select Case, or three If's ?


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop several sheets - not all worksheets of workbook al Excel Programming 8 January 25th 09 11:25 PM
Master's please help me with my code; Doing a loop to copy valuesfrom a series Sheets of another workbook.. jhong Excel Programming 2 January 25th 08 10:30 AM
apply Macro to all sheets in workbook - loop [email protected] Excel Programming 3 July 19th 07 08:13 PM
Skip LOC in D While Loop Khurram Excel Programming 2 January 30th 07 05:15 PM
Loop through all sheets in workbook jennie Excel Programming 7 October 26th 05 11:54 AM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"