Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Excluding Worksheet from Procedure

Hi,

I will be getting 30 - 40 Excel workbooks each with two sheets each. I
would like to run code on only the named sheets not ending with the
letter 'c.' Any help you can lend with this would be appreciated.

'--------------------------------------------------------------

Dim MyFile
Dim MyPath
Dim MyName

MyPath = "c:\ExcelFiles\"
MyName = Dir(MyPath, vbNormal)

Do While MyName < ""
If (GetAttr(MyPath & MyName) And vbNormal) = vbNormal Then
Application.DisplayAlerts = False
Application.Workbooks.Open (MyPath & MyName)
For Each Worksheet In ActiveWorkbook.Worksheets
If Right(Worksheet.Name, 1) = "c" Then
GoTo ExitLoop
Else

Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Replace What:=" ", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="#", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=".", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Columns("A:Ai").Select
Selection.NumberFormat = "@"
Columns("v:v").Select
Selection.NumberFormat = "#"

ActiveWorkbook.Save

ActiveWorkbook.SaveAs
Filename:="C:\ExcelFiles\Cleaned\" & Worksheet.Name & ".xls", _
FileFormat:=xlNormal, CreateBackup:=False
End If
ExitLoop:
Next Worksheet
ActiveWorkbook.Close False
End If
MyName = Dir
Loop

End Sub

'------------------------------------

Henry

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Excluding Worksheet from Procedure

Untested, but something like this. You can put it in a For each ws Next loop.

If LCase(Right(Worksheet.name,1)) < "c" then
'Do something
End If


"Henry Stockbridge" wrote:

Hi,

I will be getting 30 - 40 Excel workbooks each with two sheets each. I
would like to run code on only the named sheets not ending with the
letter 'c.' Any help you can lend with this would be appreciated.

'--------------------------------------------------------------

Dim MyFile
Dim MyPath
Dim MyName

MyPath = "c:\ExcelFiles\"
MyName = Dir(MyPath, vbNormal)

Do While MyName < ""
If (GetAttr(MyPath & MyName) And vbNormal) = vbNormal Then
Application.DisplayAlerts = False
Application.Workbooks.Open (MyPath & MyName)
For Each Worksheet In ActiveWorkbook.Worksheets
If Right(Worksheet.Name, 1) = "c" Then
GoTo ExitLoop
Else

Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Replace What:=" ", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="#", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=".", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Columns("A:Ai").Select
Selection.NumberFormat = "@"
Columns("v:v").Select
Selection.NumberFormat = "#"

ActiveWorkbook.Save

ActiveWorkbook.SaveAs
Filename:="C:\ExcelFiles\Cleaned\" & Worksheet.Name & ".xls", _
FileFormat:=xlNormal, CreateBackup:=False
End If
ExitLoop:
Next Worksheet
ActiveWorkbook.Close False
End If
MyName = Dir
Loop

End Sub

'------------------------------------

Henry


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Excluding Worksheet from Procedure

Perfect, thanks!

JLGWhiz wrote:
Untested, but something like this. You can put it in a For each ws Next loop.

If LCase(Right(Worksheet.name,1)) < "c" then
'Do something
End If


"Henry Stockbridge" wrote:

Hi,

I will be getting 30 - 40 Excel workbooks each with two sheets each. I
would like to run code on only the named sheets not ending with the
letter 'c.' Any help you can lend with this would be appreciated.

'--------------------------------------------------------------

Dim MyFile
Dim MyPath
Dim MyName

MyPath = "c:\ExcelFiles\"
MyName = Dir(MyPath, vbNormal)

Do While MyName < ""
If (GetAttr(MyPath & MyName) And vbNormal) = vbNormal Then
Application.DisplayAlerts = False
Application.Workbooks.Open (MyPath & MyName)
For Each Worksheet In ActiveWorkbook.Worksheets
If Right(Worksheet.Name, 1) = "c" Then
GoTo ExitLoop
Else

Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Replace What:=" ", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:="#", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=".", Replacement:="_", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Columns("A:Ai").Select
Selection.NumberFormat = "@"
Columns("v:v").Select
Selection.NumberFormat = "#"

ActiveWorkbook.Save

ActiveWorkbook.SaveAs
Filename:="C:\ExcelFiles\Cleaned\" & Worksheet.Name & ".xls", _
FileFormat:=xlNormal, CreateBackup:=False
End If
ExitLoop:
Next Worksheet
ActiveWorkbook.Close False
End If
MyName = Dir
Loop

End Sub

'------------------------------------

Henry



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
How can I print a worksheet excluding blank rows? lohme Excel Worksheet Functions 13 August 23rd 06 10:36 PM
Copying A Worksheet Only, Excluding the Code MWS Excel Programming 5 March 7th 06 01:51 PM
Copy worksheet excluding defined name ranges Thomas Smith[_2_] Excel Programming 2 July 11th 05 08:45 AM
Printing worksheet excluding rows with formulas LennyG Excel Programming 7 December 14th 04 07:49 PM
Print current worksheet excluding a few cells Daniel Lidström Excel Programming 3 September 10th 04 11:02 AM


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