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

One Macro multiple sheets

Status
Not open for further replies.

jjlbmcnews

IS-IT--Management
Oct 4, 2001
60
GB
Hi,

I have a macro that modifies the properties of a column within a sheet. I've set this up to use Auto_Open but it only runs on one sheet and not the other three. How can you force the macro to run on all the sheets in the workbook on open?
 
Code:
dim ws as worksheet
for each ws in thisworkbook.worksheets
' Your Macro
Code:
next ws

Peace! [peace]

Mike

Didn't get the answers that you wanted? Take a look at FAQ219-2884
 
Hi,

Thanks for the advice, I've tested this and it doesn't appear to work, code below.

Sub Auto_Open()

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Columns("B:B").Select
Selection.TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1)
Columns("B:B").EntireColumn.AutoFit
Selection.NumberFormat = "0"
Columns("B:B").EntireColumn.AutoFit

Next ws

End Sub

Am I missing something?
 
try this

Sub Auto_Open()

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
with ws
.columns("B:B").TextToColumns Destination:=.Range("B1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1)
.NumberFormat = "0"
.Columns("B:B").EntireColumn.AutoFit
end with
Next ws


Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
This should work:
Code:
Sub Auto_Open()

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
With ws.Columns("B:B")
        .TextToColumns Destination:=Range("B1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1)
    .NumberFormat = "0"
    .EntireColumn.AutoFit
End With    
Next ws

Peace! [peace]

Mike

Didn't get the answers that you wanted? Take a look at FAQ219-2884
 
Cross-Posted Geoff's :p

[cheers]



Peace! [peace]

Mike

Didn't get the answers that you wanted? Take a look at FAQ219-2884
 
Looks like we're both on a mission today Mike....
Used the same with construct and both deleted the unnecessary autofit line......

Great minds think alike....
or
Fools rarely differ...... ?????
:)

Rgds, Geoff
[blue]Si hoc signum legere potes, operis boni in rebus Latinus alacribus et fructuosis potiri potes![/blue]
Want the [red]best[/red] answers to your questions ? faq222-2244
 
Not really on a mission Geoff ;-)

It's just been awhile since I had a chance to post here and I got a little bored. My Project is "on hold" until after the holidays!

[santa] Happy Ho Ho!!! [Cheers]



Peace! [peace]

Mike

Didn't get the answers that you wanted? Take a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top