Hello everyone, I am a VBA novice (at best) and really need help with a deadline-based problem that I have been up all night trying to solve. I have a workbook with 12 worksheets about a product, lets call it Ice Cream.
I need to write simple VBA that will act on all 9 of the Ice Cream flavor worksheets (sheets 2-10) and hide rows in each of the four ranges above that have blank rows (with formulas, so really looking for "").
I came up with something that I Frankensteined together that works - but it runs VERY VERY slow (almost 2 minutes), it still filters the rows on the 3 worksheets I don't want it to touch, and it sometimes freezes up. Can anyone help me to either scrap this and start with something better (like autofiltering?), or help me make this work? Thank you!
- Worksheet 1 is a csv data dump from the Ice Cream company's sales system
- Worksheets 2 though 10 are rollup sheets of formulas with totals and averages about individual Ice Cream flavors pulling from the first worksheet
- All 9 of these worksheets are formatted exactly the same way with the same number of rows/columns of data
- All 9 of these worksheets have four separate areas that could be filtered
- D7:R157 - Ice Cream Sales
- D161:R311 - Ice Cream Marketing
- D315:R465 - Ice Cream Cost
- D469:R619 - Ice Cream Projections
- Worksheet 11 is a rollup summary of all Ice Cream flavors in its own format
- Worksheet 12 is an instructional sheet to tell end users what the data means
I need to write simple VBA that will act on all 9 of the Ice Cream flavor worksheets (sheets 2-10) and hide rows in each of the four ranges above that have blank rows (with formulas, so really looking for "").
I came up with something that I Frankensteined together that works - but it runs VERY VERY slow (almost 2 minutes), it still filters the rows on the 3 worksheets I don't want it to touch, and it sometimes freezes up. Can anyone help me to either scrap this and start with something better (like autofiltering?), or help me make this work? Thank you!
VBA Code:
Sub HideEmptyRows()
Dim lr As Long
Dim ws As Worksheet
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
For Each sh In Worksheets
If sh.Name <> "Summary" Or sh.Name <> "Weekly Report" Or sh.Name <> "Instructions" Then
sh.Activate
For i = 8 To 157
If ActiveSheet.Cells(i, 4) = "" Then
ActiveSheet.Cells(i, 4).EntireRow.Hidden = True
End If
Next i
For i = 162 To 311
If ActiveSheet.Cells(i, 4) = "" Then
ActiveSheet.Cells(i, 4).EntireRow.Hidden = True
End If
Next i
For i = 316 To 465
If ActiveSheet.Cells(i, 4) = "" Then
ActiveSheet.Cells(i, 4).EntireRow.Hidden = True
End If
Next i
For i = 470 To 619
If ActiveSheet.Cells(i, 4) = "" Then
ActiveSheet.Cells(i, 4).EntireRow.Hidden = True
End If
Next i
End If
Next sh
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub