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/
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/