Speeding up my macro by using cells that are non-blank rather than setting row numbers

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am just looking to speed up a section of one of my macros as it seems to be lagging and I perform this macro in a high stress period of my job so it would be great to speed things up. I have to perform this macro to about 20 worksheets every 2 weeks or so. Usually only 2 of the 20 sheets is actually filled with information 1000 rows down. Most often they are between 30 and 250.

Can somebody please tell me how I would refine my code to start searching and updating row heights from cell A7 downwards and getting the macro to stop performing once it reaches the first empty A cell. Currently I just set it at the maximum range to capture so that every sheet will work properly

The code is shown below:

Code:
Dim ws As Worksheet                         
Dim c As Range 


 Application.ScreenUpdating = False
 Application.Calculation = xlCalculationManual
    For Each ws In ActiveWindow.SelectedSheets
        For Each c In ws.Range("A7:A1000")
            c.EntireRow.AutoFit
            If c.RowHeight < 20 Then c.RowHeight = 20
        Next c
    Next ws
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

Any help is greatly appreciated.

Thanks,
Milos
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Code:
    Dim ws As Worksheet
    Dim c As Range
    Dim Rng As Range

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    For Each ws In ActiveWindow.SelectedSheets
        ws.Range("A7:A1000").EntireRow.AutoFit
        Set Rng = ws.Range("A7:A" & ws.Range("A" & ws.Rows.Count).End(xlUp).Row)
        For Each c In Rng
            If c.RowHeight < 20 Then c.RowHeight = 20
        Next c
    Next ws
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
 
Last edited:
Upvote 0
Thank you very much rlv01!

Works perfectly!
 
Upvote 0

Forum statistics

Threads
1,216,231
Messages
6,129,631
Members
449,522
Latest member
natalia188

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