variable vba per ws

JOEE1979

Active Member
Joined
Dec 18, 2022
Messages
287
Office Version
  1. 365
Platform
  1. Windows
I need to write a vba that will be variable to every worksheet in my book.
I want to delete the blank cells (shift cells up) in starting with AE4-AI4, and all the way down until the vba starts to see text (in this example, AE37)
AE37 is going to be different in every ws, (the columns will always remain the same, however the rows will be different)
Is this possible?

Weekday Bus Cycling - Revision 3 - done.xlsm
UVWXYZAAABACADAEAFAGAHAI
3BlockTypeOp DaySign onStartEndVehKmNoteTotal KMTimeOUTIN
4DDS4924.41
5644.82
6659.54
7764.61
8405.92
9599.54
10653.42
11403.60
12425.73
13367.24
14 
15 
16 
1700
18
19
20BlockTypeOp DaySign onStartEndVehKmNoteTotal KM
2145AC2334.37
22463.43
23531.50
24599.93
25739.51
26 
27 
28CChange off or wash bus, if required 
29MCarry the Mail 
30RPTContact supervisor for instructions 
31 
32 
3300
34
35
36
370:01-0:3000
380:31-1:0000
391:01-1:3000
401:31-2:0000
412:01-2:3000
422:31-3:0000
433:01-3:3010
443:31-4:0020
454:01-4:3010
464:31-5:0010
475:01-5:3000
485:31-6:0020
496:01-6:3010
506:31-7:0020
517:01-7:3010
527:31-8:0000
538:01-8:3000
548:31-9:0000
559:01-9:3000
569:31-10:0000
5710:01-10:3000
5810:31-11:0000
5911:01-11:3001
6011:31-12:0001
6112:01-12:3012
6212:31-13:0000
6313:01-13:3010
6413:31-14:0000
6514:01-14:3020
6614:31-15:0020
6715:01-15:3021
6815:31-16:0001
6916:01-16:3020
7016:31-17:0000
7117:01-17:3000
7217:31-18:0000
7318:01-18:3000
7418:31-19:0000
7519:01-19:3001
7619:31-20:0000
7720:01-20:3000
7820:31-21:0000
7921:01-21:3001
8021:31-22:0000
8122:01-22:3000
8222:31-23:0001
8323:01-23:3001
8423:31-0:0002
Aberfoyle-MON-WED
Cell Formulas
RangeFormula
AD4AD4=SUM(AD5:AD16)
AD5:AD16,AD22:AD32AD5=IF((SUM(H5,R5,AB5))=0,"",SUM(H5,R5,AB5))
X17,Z17X17=COUNTIF(X5:X16,">="&Planner!$C$1)
AD21AD21=SUM(AD22:AD32)
X33,Z33X33=COUNTIF(X22:X32,">="&Planner!$C$1)
AH37:AH84AH37=SUM((COUNTIFS($D$5:$D$16,">="&AE37,$D$5:$D$16,"<="&AG37))+(COUNTIFS($D$22:$D$32,">="&AE37,$D$22:$D$32,"<="&AG37))+(COUNTIFS($N$5:$N$16,">="&AE37,$N$5:$N$16,"<="&AG37))+(COUNTIFS($N$22:$N$32,">="&AE37,$N$22:$N$32,"<="&AG37))+(COUNTIFS($X$5:$X$16,">="&AE37,$X$5:$X$16,"<="&AG37))+(COUNTIFS($X$22:$X$32,">="&AE37,$X$22:$X$32,"<="&AG37)))
AI37:AI84AI37=SUM((COUNTIFS($F$5:$F$16,">="&AE37,$F$5:$F$16,"<="&AG37))+(COUNTIFS($F$22:$F$32,">="&AE37,$F$22:$F$32,"<="&AG37))+(COUNTIFS($P$5:$P$16,">="&AE37,$P$5:$P$16,"<="&AG37))+(COUNTIFS($P$22:$P$32,">="&AE37,$P$22:$P$32,"<="&AG37))+(COUNTIFS($Z$5:$Z$16,">="&AE37,$Z$5:$Z$16,"<="&AG37))+(COUNTIFS($Z$22:$Z$32,">="&AE37,$Z$22:$Z$32,"<="&AG37)))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
AI37:AI84Cell Value>0textNO
AH37:AH84Cell Value>0textNO
AH37:AI84Cell Value=0textNO
D5:D16,N5:N16,X5:X16,D22:D32,N22:N32,X22:X27,X31:X32Expression=D5=$N$1textNO
D5:D16,N5:N16,X5:X16,D22:D32,N22:N32,X22:X27,X31:X32Cell Valuebetween Planner!$C$1 and $N$1textNO
D5:D16,N5:N16,X5:X16,D22:D32,N22:N32,X22:X27,X31:X32Cell Value>Planner!$C$1textNO
F5:F16,P5:P16,Z5:Z16,F22:F32,P22:P32,Z22:Z27,Z31:Z32Cell Value>Planner!$C$1textNO
 

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).
Try this on a copy of your workbook.
VBA Code:
Sub JOEE1979()
    Dim ws As Worksheet, rng As Range, LRow As Long
    
    For Each ws In ThisWorkbook.Worksheets
        LRow = ws.Cells(Rows.Count, "AE").End(xlUp).Row
        Set rng = ws.Range("AE4:AI" & LRow).SpecialCells(xlCellTypeBlanks)
        rng.Delete shift:=xlUp
    Next ws
End Sub
 
Upvote 0
Try this on a copy of your workbook.
VBA Code:
Sub JOEE1979()
    Dim ws As Worksheet, rng As Range, LRow As Long
   
    For Each ws In ThisWorkbook.Worksheets
        LRow = ws.Cells(Rows.Count, "AE").End(xlUp).Row
        Set rng = ws.Range("AE4:AI" & LRow).SpecialCells(xlCellTypeBlanks)
        rng.Delete shift:=xlUp
    Next ws
End Sub
"no cells found"
and then highlights "Set rng = ws.Range("AE4:AI" & LRow).SpecialCells(xlCellTypeBlanks)"
 
Upvote 0
Sorry Joe, I assumed all your sheets had blank cells in that range. I'm away from my normal laptop for a few hours so I can't test this, but give this variation a try.
VBA Code:
Sub JOEE1979_V2()
    Dim ws As Worksheet, rng As Range, LRow As Long
    
    For Each ws In ThisWorkbook.Worksheets
        If ws.Range("AE4") = "" Then
            LRow = ws.Cells(Rows.Count, "AE").End(xlUp).Row
            Set rng = ws.Range("AE4:AI" & LRow).SpecialCells(xlCellTypeBlanks)
            rng.Delete shift:=xlUp
        End If
    Next ws
End Sub
 
Upvote 0
Solution
Sorry Joe, I assumed all your sheets had blank cells in that range. I'm away from my normal laptop for a few hours so I can't test this, but give this variation a try.
VBA Code:
Sub JOEE1979_V2()
    Dim ws As Worksheet, rng As Range, LRow As Long
   
    For Each ws In ThisWorkbook.Worksheets
        If ws.Range("AE4") = "" Then
            LRow = ws.Cells(Rows.Count, "AE").End(xlUp).Row
            Set rng = ws.Range("AE4:AI" & LRow).SpecialCells(xlCellTypeBlanks)
            rng.Delete shift:=xlUp
        End If
    Next ws
End Sub
worked, awesome, thanks
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,857
Members
452,361
Latest member
d3ad3y3

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