looping formatting multiple sheets

I

ian bartlett

I'm sure I can accomplish this with the macro recorder, but it would
generate a ton of unneccesary code.

I import a text file into Excel 2003 then using Debra's (Contexture's) copy
to different sheets macro I end up with 34 sheets (including the original,
but I'd like all sheet in the workbook formatted no matter the number, which
could possibly change)

I'd like to

1. Header row A1:S1 row height 15 font red bold, background yellow
2. Remainder or rows height 78
3. Then insert a column not sure of syntax, manually click column C then
insert column

Thanks for any and all help

Ian
 
R

Rick Rothstein \(MVP - VB\)

This code should do what you asked...

With Worksheets("Sheet1")
.Rows().RowHeight = 78
.Rows(1).RowHeight = 15
.Columns("C").Insert
With .Range("A1:S1")
.Font.Bold = True
.Font.Color = vbRed
.Cells.Interior.Color = vbYellow
End With
End With

Note that I am executing your Column Insert request before the formatting is
applied to A1:S1... if you do it afterwards, the insert operation will
extend the formats to Column T.

Rick
 
I

ian bartlett

Rick

I'm not that well versed but I don't think it will do all the sheets ?

Thanks for you input
Ian
 
R

Rick Rothstein \(MVP - VB\)

Give this a try...

Dim SH As Worksheet
For Each SH In Worksheets
With Worksheets(SH)
.Rows().RowHeight = 78
.Rows(1).RowHeight = 15
.Columns("C").Insert
With .Range("A1:S1")
.Font.Bold = True
.Font.Color = vbRed
.Cells.Interior.Color = vbYellow
End With
End With
Next

Rick
 
R

Rick Rothstein \(MVP - VB\)

You are welcome. For future questions you might post, you should post back
to the message you are responding to rather than posting back to your
original message. It makes the thread easier to follow (especially for
someone who may read it at some future date in the Google archives).

Rick
 
I

ian bartlett

I spoke to soon Rick I'm getting an error noted in body

Public Sub Fix_Up_Sheets()
Dim SH As Worksheet
For Each SH In Worksheets
With Worksheets(SH) 'error at this line Type mismatch Placed in regular
module
.Rows().RowHeight = 78
.Rows(1).RowHeight = 15
.Columns("C").Insert
With .Range("A1:S1")
.Font.Bold = True
.Font.Color = vbRed
.Cells.Interior.Color = vbYellow
End With
End With
Next

End Sub
 
R

Rick Rothstein \(MVP - VB\)

Sorry... I forgot that I declared SH as a Worksheet... the Worksheets()
property "housing" is not required in the With statement. This code should
work....

Public Sub Fix_Up_Sheets()
Dim SH As Worksheet
For Each SH In Worksheets
With SH
.Rows().RowHeight = 78
.Rows(1).RowHeight = 15
.Columns("C").Insert
With .Range("A1:S1")
.Font.Bold = True
.Font.Color = vbRed
.Cells.Interior.Color = vbYellow
End With
End With
Next
End Sub

Rick
 
I

ian bartlett

Rick

I can't pretend to understand this but it is working as advertised!!

Thanks again
 

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