Just out of curiousity, why didn't this work (a change perpetuated to all sheets)?

P

Per Jessen

Hi

You are missing a single dot before cells.select to set the reference
to ws, ie it should read:

..Cells.Select

I would also skip the select statement as it slows down your code.

Sub Change_for_ALL_Worksheets()
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
With ws
'-----------------------------------------------------------------------
'.With Statement code STARTS here below:
With .Cells
.VerticalAlignment = xlCenter
End With
'.With Statement code ENDS here above.
'-----------------------------------------------------------------------
End With
Next ws
End Sub

Hopes this helps
.....
Per
 
S

StargateFan

I found the following script, with my line of coding in the middle. I
was just trying to make all the sheets have horizontal alignment in
them. After running this, the sheets remained with the alignment they
had. I'm just curious as to how you'd script something that would run
through all the sheets.

I'm hoping/guessing that this could be a permanent, re-usable script
in our Personal.xls. Once we find code that works on one sheet,
hopefully we could plug it into the middle, below, and the action
would be repeated on all sheets (?).

I searched and searched and this is about the only script that came
up that _seemed_ to be a good base to have to re-do, as needed.

Anyway, thanks!




Sub Change_for_ALL_Worksheets()
Dim ws As Worksheet

For Each ws In Worksheets
With ws
'-----------------------------------------------------------------------
'.With Statement code STARTS here below:
Cells.Select
With Selection
.VerticalAlignment = xlCenter
End With
'.With Statement code ENDS here above.
'-----------------------------------------------------------------------
End With
Next ws
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top