VBA Row 2:2 wrap text on all sheets that start with Data (Code included)

LNG2013

Active Member
Joined
May 23, 2011
Messages
465
Hello I am trying to wrap text on all rows 2:2 on all sheets that have the name Data.

Any help would be appreciated.

VBA Code:
Sub WrapRow2()

Dim sh As Worksheet

For Each sh In ThisWorkbook.Worksheets

    If UCase(Left(sh.Name, 4)) = "DATA" Then

        With Rows("2:2")
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = True
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With

    End If

Next

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Just add the reference to the sheet on this line:

Rich (BB code):
With sh.Rows("2:2")
 
Upvote 0
Your sheet names must start with "DATA..."
You can put here the names of your sheets.

And also test the macro step by step, run the macro by pressing F8 and check what the code is doing.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,582
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top