Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop to infinity 1

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I have created a loop that I can't get out of. I have a multiple worksheet excel file. With help I have created a loop that does work to loop thru all the worksheets. Now I want specific things to be done to one worksheet and not to the others. This is when my problems started.

Here is my code

/code/
Sub FormatLong()
'
' FormatLong Macro
' Macro recorded 3/6/2009

Dim ws As Worksheet

For Each ws In Worksheets
With ws
.Activate

If Sheets("BulkQuotesXL Settings").Select Then
Columns("A").Select
With Selection
.NumberFormat = "text"
.Columns.AutoFit
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Columns("B:C").Select
With Selection
.NumberFormat = "mm/dd/yyyy"
.Columns.AutoFit
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Columns("F").Select
With Selection
.NumberFormat = "#,##0"
.Columns.AutoFit
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlRight
End With

Else
Rows("2:2").Select
ActiveWindow.FreezePanes = True
Columns("A").Select
With Selection
.NumberFormat = "mm/dd/yyyy"
.Columns.AutoFit
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Columns("B:E").Select
With Selection
.NumberFormat = "0.00"
.Columns.AutoFit
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With

Columns("F").Select
With Selection
.NumberFormat = "#,##0"
.Columns.AutoFit
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlRight
End With

R1 = ActiveSheet.UsedRange.Rows.Count
R2 = "F" & R1
SR = R1 - 22
ActiveWindow.ScrollRow = SR
Range(R2).Select

End If

End With
Next

'
End Sub
/code/


 


Hi,

/code/

Use TGML Tage. Search on THIS PAGE for TGML and use the CODE tag.
Now I want specific things to be done to one worksheet and not to the others.
Code:
dim ws as worksheet
for each ws in worksheets
  with ws
    select case .name
       case "YourSpecialSheetName"
         'do something SPECIAL SHEET here
       case else  'all other sheets
         'do something for ALL OTHER SHEETS here
    end select
    'do something for ALL SHEETS here
  end with
next




Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I must have misunderstood the post on putting tags on code.
You want /code/ in front of all the lines?

Tom
 



Did you SEARCH on this page for the TGML LINK?

Did you see what my CODE posting looked like, using TGML Tags?

I did not say anything about using /code/.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I just clicked on the process TGML function on the bottom of the page. I did not see this before. This is the way I will submt my next question. As a newbie I am sorry. Thanks for all your help.
 



Nor problem. We all have to learn something new from time to time.

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


Yep, sonny!

Skip,
[glasses]Don't let the Diatribe...
talk you to death![tongue]

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Especially us old dudes! I have forgotten more than I can remember.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top