Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Exclude specific wks in FOR EACH wks Loop

The FOR EACH loop that I show below works terrific for going thru ALL tabs
and performing an operation on each one. I would like to keep the same FOR
EACH statement and be able to exclude say Sheet75 and Sheet85 from that loop.
Are there any suggestions, your help is much appreciated. Thx - Dean

Dim lRealLastRow As Long
Dim lRealLastColumn As Long
Dim wks As Worksheet
For Each wks In Worksheets
wks.Select
LastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count
wks.Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Copy
Sheets("Complete list").Select
Range("A1").Select
On Error Resume Next
lRealLastRow = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByRows, xlPrevious).Row + 2
lRealLastColumn = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByColumns, xlPrevious).Column
Cells(lRealLastRow, 1).Select
ActiveSheet.Paste
Next wks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Exclude specific wks in FOR EACH wks Loop

As long as those two sheets have not been renamed try this:

For Each wks In Worksheets
If wks.Name < "Sheet75" And wks.Name < "Sheet85" Then
....
End If
Next wks


"Dean" wrote:

The FOR EACH loop that I show below works terrific for going thru ALL tabs
and performing an operation on each one. I would like to keep the same FOR
EACH statement and be able to exclude say Sheet75 and Sheet85 from that loop.
Are there any suggestions, your help is much appreciated. Thx - Dean

Dim lRealLastRow As Long
Dim lRealLastColumn As Long
Dim wks As Worksheet
For Each wks In Worksheets
wks.Select
LastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count
wks.Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Copy
Sheets("Complete list").Select
Range("A1").Select
On Error Resume Next
lRealLastRow = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByRows, xlPrevious).Row + 2
lRealLastColumn = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByColumns, xlPrevious).Column
Cells(lRealLastRow, 1).Select
ActiveSheet.Paste
Next wks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Exclude specific wks in FOR EACH wks Loop

Charlie,
Great response. One issue I'm thinking of, the names of the Sheets are not
Sheet75 and Sheet85, that is their code names. Would the < statement
change then, that is to use the Code Names instead of Sheet names? Thx
again. Dean

"Charlie" wrote:

As long as those two sheets have not been renamed try this:

For Each wks In Worksheets
If wks.Name < "Sheet75" And wks.Name < "Sheet85" Then
...
End If
Next wks


"Dean" wrote:

The FOR EACH loop that I show below works terrific for going thru ALL tabs
and performing an operation on each one. I would like to keep the same FOR
EACH statement and be able to exclude say Sheet75 and Sheet85 from that loop.
Are there any suggestions, your help is much appreciated. Thx - Dean

Dim lRealLastRow As Long
Dim lRealLastColumn As Long
Dim wks As Worksheet
For Each wks In Worksheets
wks.Select
LastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count
wks.Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Copy
Sheets("Complete list").Select
Range("A1").Select
On Error Resume Next
lRealLastRow = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByRows, xlPrevious).Row + 2
lRealLastColumn = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByColumns, xlPrevious).Column
Cells(lRealLastRow, 1).Select
ActiveSheet.Paste
Next wks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Exclude specific wks in FOR EACH wks Loop

Yes, in fact I never reference the sheet objects (Sheet1, Sheet2, etc.)
directly. I prefer to reference them as Sheets("Sheet1") or Sheets("Whatever")

In your case put in the real sheet names in the quotes:

If wks.Name < "MySheet75" ... Then


"Dean" wrote:

Charlie,
Great response. One issue I'm thinking of, the names of the Sheets are not
Sheet75 and Sheet85, that is their code names. Would the < statement
change then, that is to use the Code Names instead of Sheet names? Thx
again. Dean

"Charlie" wrote:

As long as those two sheets have not been renamed try this:

For Each wks In Worksheets
If wks.Name < "Sheet75" And wks.Name < "Sheet85" Then
...
End If
Next wks


"Dean" wrote:

The FOR EACH loop that I show below works terrific for going thru ALL tabs
and performing an operation on each one. I would like to keep the same FOR
EACH statement and be able to exclude say Sheet75 and Sheet85 from that loop.
Are there any suggestions, your help is much appreciated. Thx - Dean

Dim lRealLastRow As Long
Dim lRealLastColumn As Long
Dim wks As Worksheet
For Each wks In Worksheets
wks.Select
LastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count
wks.Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Copy
Sheets("Complete list").Select
Range("A1").Select
On Error Resume Next
lRealLastRow = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByRows, xlPrevious).Row + 2
lRealLastColumn = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByColumns, xlPrevious).Column
Cells(lRealLastRow, 1).Select
ActiveSheet.Paste
Next wks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Exclude specific wks in FOR EACH wks Loop

Charlie,
I tried the statement Sheet75.name, it worked perfectly for Code Name use.
Thx so much for your help. This is great ! Dean

"Dean" wrote:

Charlie,
Great response. One issue I'm thinking of, the names of the Sheets are not
Sheet75 and Sheet85, that is their code names. Would the < statement
change then, that is to use the Code Names instead of Sheet names? Thx
again. Dean

"Charlie" wrote:

As long as those two sheets have not been renamed try this:

For Each wks In Worksheets
If wks.Name < "Sheet75" And wks.Name < "Sheet85" Then
...
End If
Next wks


"Dean" wrote:

The FOR EACH loop that I show below works terrific for going thru ALL tabs
and performing an operation on each one. I would like to keep the same FOR
EACH statement and be able to exclude say Sheet75 and Sheet85 from that loop.
Are there any suggestions, your help is much appreciated. Thx - Dean

Dim lRealLastRow As Long
Dim lRealLastColumn As Long
Dim wks As Worksheet
For Each wks In Worksheets
wks.Select
LastRow = ActiveSheet.UsedRange.Row - 1 +
ActiveSheet.UsedRange.Rows.Count
wks.Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Copy
Sheets("Complete list").Select
Range("A1").Select
On Error Resume Next
lRealLastRow = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByRows, xlPrevious).Row + 2
lRealLastColumn = Cells.Find("*", Range("A1"), xlFormulas, ,
xlByColumns, xlPrevious).Column
Cells(lRealLastRow, 1).Select
ActiveSheet.Paste
Next wks

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
Exclude specific cell from entire column Dn_ New Users to Excel 2 March 30th 06 09:23 PM
Loop through specific worksheets Ben Excel Programming 4 November 27th 05 02:37 PM
Macro/Loop If Statement Help -delete the row with the specific te Bricktop Excel Programming 5 October 28th 05 09:50 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM


All times are GMT +1. The time now is 05:46 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"