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 strongm 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
Nov 7, 2000
20
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
 

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