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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through Excel workbook to center(Please Help) 1

Status
Not open for further replies.

missprogrammer

Programmer
Joined
Nov 7, 2000
Messages
20
Location
US
I'm having problems with my code, Im getting a compile error
next without for. What am i missing I trying to loop the code through the workbook on all the sheets

Please help,Thanks in advance


Private Sub CenterCells()
Dim c As Integer

For c = 1 To ActiveWorkbook.Sheets.Count
With ActiveWorkbook.Sheets(c)
Range("B1:AE48").HorizontalAlignment = xlCenter
' Range("B1:AE48").VerticalAlignment = xlBottom
' Range("B1:AE48").Orientation = 0
' Range("B1:AE48").AddIndent = False
' Range("B1:AE48").ShrinkToFit = False
' Range("B1:AE48").MergeCells = False



Next c
End With
End Sub
 
The End With needs to be before the Next c.
 

its not looping through the entire workbook, that is it is center that last active worksheet, but not all of them

Private Sub CenterCells()
Dim c As Integer

For c = 1 To ActiveWorkbook.Sheets.Count
With ActiveWorkbook.Sheets(c)
Range("B1:AE48").HorizontalAlignment = xlCenter

End With
Next c
' Next Counter
End Sub


 
Just responded to your latest post:
Code:
    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Sheets
        ws.Range("B1:AE48").HorizontalAlignment = xlCenter
    Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top