Specify Minimum Row Height And Autofit Row Size for ALL worksheets

Laurence D

New Member
Joined
Sep 14, 2016
Messages
31
Hello experts,

I have a workbook with the same kind of data in about 30 different worksheet tabs. I want to make all of the rows with data in each worksheet be reformatted with a row height of 30, unless the content is larger than 30 then it needs the entire row to be autofitted. I have code that works for one active sheet.

But want I need help with is additional code that will make my code work with all worksheets in this workbook.

Can anybody help with this? Here is my code so far:

Code:
[COLOR=#000000][FONT=Menlo]Sub MinimumRow_Plus_Autofit()[/FONT][/COLOR]
[FONT=Menlo]
[/FONT]
[COLOR=#000000][FONT=Menlo] Application.ScreenUpdating = [COLOR=#011993]False[/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo][COLOR=#011993]For[/COLOR] [COLOR=#011993]Each[/COLOR] c [COLOR=#011993]In[/COLOR] Range("A1:A300")[/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo]    c.EntireRow.AutoFit[/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo]    [COLOR=#011993]If[/COLOR] c.RowHeight < 30 [COLOR=#011993]Then[/COLOR] c.RowHeight = 30[/FONT][/COLOR]
[COLOR=#011993][FONT=Menlo]Next[COLOR=#000000] c[/COLOR][/FONT][/COLOR]
[FONT=Menlo]
[/FONT]
[COLOR=#000000][FONT=Menlo]Application.ScreenUpdating = [COLOR=#011993]True[/COLOR][/FONT][/COLOR]
[COLOR=#011993][FONT=Menlo]End[COLOR=#000000] [/COLOR]Sub[/FONT][/COLOR]

Thanks all,
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Code:
Sub MinimumRow_Plus_Autofit()

Dim ws As Worksheet
Dim c As Range

    Application.ScreenUpdating = False
    For Each ws In ThisWorkbook.Worksheets
        For Each c In ws.Range("A1:A300")
            c.EntireRow.AutoFit
            If c.RowHeight < 30 Then c.RowHeight = 30
        Next c
    Next ws
    
    Application.ScreenUpdating = True
EndSub
 
Last edited:
Upvote 0
Hello again,

I have been trying this code out with large numbers of worksheets (50 to 100 worksheets) and it is functional but is really slow at performing the assigned task (e.g. taking more than 5 minutes each run!!). Is there a way to make this code more efficient as I assume the way that the macro is written is chunky and slowing the process?

For it to work perfectly for me I need the macro to find all non-blank rows in columns A:G (each worksheet is no more than 300 rows down) and then perform the above coding.

Appreciate any help,

Thanks
 
Upvote 0
I can only assume there's a lot of calculating going on in the background. Try this:

Code:
Sub MinimumRow_Plus_Autofit()

Dim ws As Worksheet
Dim c As Range


    Application.ScreenUpdating = False
    [COLOR=#ff0000][B]Application.Calculation = xlCalculationManual[/B][/COLOR]
    For Each ws In ThisWorkbook.Worksheets
        For Each c In ws.Range("A1:A300")
            c.EntireRow.AutoFit
            If c.RowHeight < 30 Then c.RowHeight = 30
        Next c
    Next ws
    [B][COLOR=#ff0000]Application.Calculation = xlCalculationAutomatic[/COLOR][/B]
    Application.ScreenUpdating = True
EndSub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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