compile error: Block If without End If

bvanzile1

New Member
Joined
Dec 8, 2017
Messages
3
I have this code to hide and unhide rows and final got it to work on one sheet, but after adding the other 5 sheets now I am getting a compile error: Block If without End If....I am enew o VA so I am sure I am missing soothing simple, thanks for your help!!

Bob

Here is the code:


Code:
Sub HideRows()
If Sheets("Batch 1").Range("D7").Value = "0" Then
    Sheets("Batch 1").Rows("7").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D7").Value > "0" Then
    Sheets("Batch 1").Rows("7").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D8").Value = "0" Then
    Sheets("Batch 1").Rows("8").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D8").Value > "0" Then
    Sheets("Batch 1").Rows("8").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D9").Value = "0" Then
    Sheets("Batch 1").Rows("9").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D9").Value > "0" Then
    Sheets("Batch 1").Rows("9").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D10").Value = "0" Then
    Sheets("Batch 1").Rows("10").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D10").Value > "0" Then
    Sheets("Batch 1").Rows("10").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D11").Value = "0" Then
    Sheets("Batch 1").Rows("11").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D11").Value > "0" Then
    Sheets("Batch 1").Rows("11").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D12").Value = "0" Then
    Sheets("Batch 1").Rows("12").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D12").Value > "0" Then
    Sheets("Batch 1").Rows("12").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D13").Value = "0" Then
    Sheets("Batch 1").Rows("13").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D13").Value > "0" Then
    Sheets("Batch 1").Rows("13").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D14").Value = "0" Then
    Sheets("Batch 1").Rows("14").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D14").Value > "0" Then
    Sheets("Batch 1").Rows("14").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D15").Value = "0" Then
    Sheets("Batch 1").Rows("15").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D15").Value > "0" Then
    Sheets("Batch 1").Rows("15").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D16").Value = "0" Then
    Sheets("Batch 1").Rows("16").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D16").Value > "0" Then
    Sheets("Batch 1").Rows("16").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D17").Value = "0" Then
    Sheets("Batch 1").Rows("17").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D17").Value > "0" Then
    Sheets("Batch 1").Rows("17").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D18").Value = "0" Then
    Sheets("Batch 1").Rows("18").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D18").Value > "0" Then
    Sheets("Batch 1").Rows("18").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D19").Value = "0" Then
    Sheets("Batch 1").Rows("19").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D19").Value > "0" Then
    Sheets("Batch 1").Rows("19").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D20").Value = "0" Then
    Sheets("Batch 1").Rows("20").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D20").Value > "0" Then
    Sheets("Batch 1").Rows("20").EntireRow.Hidden = False
If Sheets("Batch 1").Range("D21").Value = "0" Then
    Sheets("Batch 1").Rows("21").EntireRow.Hidden = True
ElseIf Sheets("Batch 1").Range("D21").Value > "0" Then
    Sheets("Batch 1").Rows("21").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D7").Value = "0" Then
        Sheets("Batch 2").Rows("7").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D7").Value > "0" Then
        Sheets("Batch 2").Rows("7").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D8").Value = "0" Then
        Sheets("Batch 2").Rows("8").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D8").Value > "0" Then
        Sheets("Batch 2").Rows("8").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D9").Value = "0" Then
        Sheets("Batch 2").Rows("9").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D9").Value > "0" Then
        Sheets("Batch 2").Rows("9").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D10").Value = "0" Then
        Sheets("Batch 2").Rows("10").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D10").Value > "0" Then
        Sheets("Batch 2").Rows("10").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D11").Value = "0" Then
        Sheets("Batch 2").Rows("11").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D11").Value > "0" Then
        Sheets("Batch 2").Rows("11").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D12").Value = "0" Then
        Sheets("Batch 2").Rows("12").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D12").Value > "0" Then
        Sheets("Batch 2").Rows("12").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D13").Value = "0" Then
        Sheets("Batch 2").Rows("13").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D13").Value > "0" Then
        Sheets("Batch 2").Rows("13").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D14").Value = "0" Then
        Sheets("Batch 2").Rows("14").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D14").Value > "0" Then
        Sheets("Batch 2").Rows("14").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D15").Value = "0" Then
        Sheets("Batch 2").Rows("15").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D15").Value > "0" Then
        Sheets("Batch 2").Rows("15").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D16").Value = "0" Then
        Sheets("Batch 2").Rows("16").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D16").Value > "0" Then
        Sheets("Batch 2").Rows("16").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D17").Value = "0" Then
        Sheets("Batch 2").Rows("17").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D17").Value > "0" Then
        Sheets("Batch 2").Rows("17").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D18").Value = "0" Then
        Sheets("Batch 2").Rows("18").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D18").Value > "0" Then
        Sheets("Batch 2").Rows("18").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D19").Value = "0" Then
        Sheets("Batch 2").Rows("19").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D19").Value > "0" Then
        Sheets("Batch 2").Rows("19").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D20").Value = "0" Then
        Sheets("Batch 2").Rows("20").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D20").Value > "0" Then
        Sheets("Batch 2").Rows("20").EntireRow.Hidden = False
    If Sheets("Batch 2").Range("D21").Value = "0" Then
        Sheets("Batch 2").Rows("21").EntireRow.Hidden = True
    ElseIf Sheets("Batch 2").Range("D21").Value > "0" Then
        Sheets("Batch 2").Rows("21").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D7").Value = "0" Then
            Sheets("Batch 3").Rows("7").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D7").Value > "0" Then
            Sheets("Batch 3").Rows("7").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D8").Value = "0" Then
            Sheets("Batch 3").Rows("8").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D8").Value > "0" Then
            Sheets("Batch 3").Rows("8").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D9").Value = "0" Then
            Sheets("Batch 3").Rows("9").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D9").Value > "0" Then
            Sheets("Batch 3").Rows("9").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D10").Value = "0" Then
            Sheets("Batch 3").Rows("10").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D10").Value > "0" Then
            Sheets("Batch 3").Rows("10").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D11").Value = "0" Then
            Sheets("Batch 3").Rows("11").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D11").Value > "0" Then
            Sheets("Batch 3").Rows("11").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D12").Value = "0" Then
            Sheets("Batch 3").Rows("12").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D12").Value > "0" Then
            Sheets("Batch 3").Rows("12").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D13").Value = "0" Then
            Sheets("Batch 3").Rows("13").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D13").Value > "0" Then
            Sheets("Batch 3").Rows("13").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D14").Value = "0" Then
            Sheets("Batch 3").Rows("14").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D14").Value > "0" Then
            Sheets("Batch 3").Rows("14").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D15").Value = "0" Then
            Sheets("Batch 3").Rows("15").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D15").Value > "0" Then
            Sheets("Batch 3").Rows("15").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D16").Value = "0" Then
            Sheets("Batch 3").Rows("16").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D16").Value > "0" Then
            Sheets("Batch 3").Rows("16").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D17").Value = "0" Then
            Sheets("Batch 3").Rows("17").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D17").Value > "0" Then
            Sheets("Batch 3").Rows("17").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D18").Value = "0" Then
            Sheets("Batch 3").Rows("18").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D18").Value > "0" Then
            Sheets("Batch 3").Rows("18").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D19").Value = "0" Then
            Sheets("Batch 3").Rows("19").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D19").Value > "0" Then
            Sheets("Batch 3").Rows("19").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D20").Value = "0" Then
            Sheets("Batch 3").Rows("20").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D20").Value > "0" Then
            Sheets("Batch 3").Rows("20").EntireRow.Hidden = False
        If Sheets("Batch 3").Range("D21").Value = "0" Then
            Sheets("Batch 3").Rows("21").EntireRow.Hidden = True
        ElseIf Sheets("Batch 3").Range("D21").Value > "0" Then
            Sheets("Batch 3").Rows("21").EntireRow.Hidden = False
                If Sheets("Batch 4").Range("D7").Value = "0" Then
                Sheets("Batch 4").Rows("7").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D7").Value > "0" Then
                Sheets("Batch 4").Rows("7").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D8").Value = "0" Then
                Sheets("Batch 4").Rows("8").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D8").Value > "0" Then
                Sheets("Batch 4").Rows("8").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D9").Value = "0" Then
                Sheets("Batch 4").Rows("9").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D9").Value > "0" Then
                Sheets("Batch 4").Rows("9").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D10").Value = "0" Then
                Sheets("Batch 4").Rows("10").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D10").Value > "0" Then
                Sheets("Batch 4").Rows("10").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D11").Value = "0" Then
                Sheets("Batch 4").Rows("11").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D11").Value > "0" Then
                Sheets("Batch 4").Rows("11").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D12").Value = "0" Then
                Sheets("Batch 4").Rows("12").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D12").Value > "0" Then
                Sheets("Batch 4").Rows("12").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D13").Value = "0" Then
                Sheets("Batch 4").Rows("13").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D13").Value > "0" Then
                Sheets("Batch 4").Rows("13").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D14").Value = "0" Then
                Sheets("Batch 4").Rows("14").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D14").Value > "0" Then
                Sheets("Batch 4").Rows("14").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D15").Value = "0" Then
                Sheets("Batch 4").Rows("15").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D15").Value > "0" Then
                Sheets("Batch 4").Rows("15").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D16").Value = "0" Then
                Sheets("Batch 4").Rows("16").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D16").Value > "0" Then
                Sheets("Batch 4").Rows("16").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D17").Value = "0" Then
                Sheets("Batch 4").Rows("17").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D17").Value > "0" Then
                Sheets("Batch 4").Rows("17").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D18").Value = "0" Then
                Sheets("Batch 4").Rows("18").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D18").Value > "0" Then
                Sheets("Batch 4").Rows("18").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D19").Value = "0" Then
                Sheets("Batch 4").Rows("19").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D19").Value > "0" Then
                Sheets("Batch 4").Rows("19").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D20").Value = "0" Then
                Sheets("Batch 4").Rows("20").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D20").Value > "0" Then
                Sheets("Batch 4").Rows("20").EntireRow.Hidden = False
            If Sheets("Batch 4").Range("D21").Value = "0" Then
                Sheets("Batch 4").Rows("21").EntireRow.Hidden = True
            ElseIf Sheets("Batch 4").Range("D21").Value > "0" Then
                Sheets("Batch 4").Rows("21").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D7").Value = "0" Then
                    Sheets("Batch 5").Rows("7").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D7").Value > "0" Then
                    Sheets("Batch 5").Rows("7").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D8").Value = "0" Then
                    Sheets("Batch 5").Rows("8").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D8").Value > "0" Then
                    Sheets("Batch 5").Rows("8").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D9").Value = "0" Then
                    Sheets("Batch 5").Rows("9").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D9").Value > "0" Then
                    Sheets("Batch 5").Rows("9").EntireRow.Hidden = False
                If Sheets("Batch5").Range("D10").Value = "0" Then
                    Sheets("Batch 5").Rows("10").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D10").Value > "0" Then
                    Sheets("Batch 5").Rows("10").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D11").Value = "0" Then
                    Sheets("Batch 5").Rows("11").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D11").Value > "0" Then
                    Sheets("Batch 5").Rows("11").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D12").Value = "0" Then
                    Sheets("Batch 5").Rows("12").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D12").Value > "0" Then
                    Sheets("Batch 5").Rows("12").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D13").Value = "0" Then
                    Sheets("Batch 5").Rows("13").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D13").Value > "0" Then
                    Sheets("Batch 5").Rows("13").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D14").Value = "0" Then
                    Sheets("Batch 5").Rows("14").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D14").Value > "0" Then
                    Sheets("Batch 5").Rows("14").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D15").Value = "0" Then
                    Sheets("Batch 5").Rows("15").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D15").Value > "0" Then
                    Sheets("Batch 5").Rows("15").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D16").Value = "0" Then
                    Sheets("Batch 5").Rows("16").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D16").Value > "0" Then
                    Sheets("Batch 5").Rows("16").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D17").Value = "0" Then
                    Sheets("Batch 5").Rows("17").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D17").Value > "0" Then
                    Sheets("Batch 5").Rows("17").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D18").Value = "0" Then
                    Sheets("Batch 5").Rows("18").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D18").Value > "0" Then
                    Sheets("Batch 5").Rows("18").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D19").Value = "0" Then
                    Sheets("Batch 5").Rows("19").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D19").Value > "0" Then
                    Sheets("Batch 5").Rows("19").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D20").Value = "0" Then
                    Sheets("Batch 5").Rows("20").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D20").Value > "0" Then
                    Sheets("Batch 5").Rows("20").EntireRow.Hidden = False
                If Sheets("Batch 5").Range("D21").Value = "0" Then
                    Sheets("Batch 5").Rows("21").EntireRow.Hidden = True
                ElseIf Sheets("Batch 5").Range("D21").Value > "0" Then
                    Sheets("Batch 5").Rows("21").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D7").Value = "0" Then
                        Sheets("Batch 6").Rows("7").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D7").Value > "0" Then
                        Sheets("Batch 6").Rows("7").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D8").Value = "0" Then
                        Sheets("Batch 6").Rows("8").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D8").Value > "0" Then
                        Sheets("Batch 6").Rows("8").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D9").Value = "0" Then
                        Sheets("Batch 6").Rows("9").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D9").Value > "0" Then
                        Sheets("Batch 6").Rows("9").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D10").Value = "0" Then
                        Sheets("Batch 6").Rows("10").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D10").Value > "0" Then
                        Sheets("Batch 6").Rows("10").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D11").Value = "0" Then
                        Sheets("Batch 6").Rows("11").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D11").Value > "0" Then
                        Sheets("Batch 6").Rows("11").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D12").Value = "0" Then
                        Sheets("Batch 6").Rows("12").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D12").Value > "0" Then
                        Sheets("Batch 6").Rows("12").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D13").Value = "0" Then
                        Sheets("Batch 6").Rows("13").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D13").Value > "0" Then
                        Sheets("Batch 6").Rows("13").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D14").Value = "0" Then
                        Sheets("Batch 6").Rows("14").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D14").Value > "0" Then
                        Sheets("Batch 6").Rows("14").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D15").Value = "0" Then
                        Sheets("Batch 6").Rows("15").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D15").Value > "0" Then
                        Sheets("Batch 6").Rows("15").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D16").Value = "0" Then
                        Sheets("Batch 6").Rows("16").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D16").Value > "0" Then
                        Sheets("Batch 6").Rows("16").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D17").Value = "0" Then
                        Sheets("Batch 6").Rows("17").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D17").Value > "0" Then
                        Sheets("Batch 6").Rows("17").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D18").Value = "0" Then
                        Sheets("Batch 6").Rows("18").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D18").Value > "0" Then
                        Sheets("Batch 6").Rows("18").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D19").Value = "0" Then
                        Sheets("Batch 6").Rows("19").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D19").Value > "0" Then
                        Sheets("Batch 6").Rows("19").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D20").Value = "0" Then
                        Sheets("Batch 6").Rows("20").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D20").Value > "0" Then
                        Sheets("Batch 6").Rows("20").EntireRow.Hidden = False
                    If Sheets("Batch 6").Range("D21").Value = "0" Then
                        Sheets("Batch 6").Rows("21").EntireRow.Hidden = True
                    ElseIf Sheets("Batch 6").Range("D21").Value > "0" Then
                        Sheets("Batch 6").Rows("21").EntireRow.Hidden = False
    

End If
    End If
        End If
            End If
                End If
                    End If
                    

End Sub
 
Last edited by a moderator:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
The End If needs to be at the end of Each If section not all at the end of the code.
However, you have a lot of code. At a glance, it looks like you could simplify that a lot by using For Next loops.
 
Upvote 0
You made no reference to < 0 so I'm assuming that is not an option.

I believe your whole code could be reduced to this:

Code:
Sub test()
Dim x As Long, ws As Worksheet
For Each ws In Worksheets(Array("Batch 1", "Batch 2", "Batch 3", "Batch 4", "Batch 5", "Batch 6"))
    For x = 7 To 21
        ws.Rows(x).Hidden = (ws.Range("D" & x) = 0)
    Next x
Next ws
End Sub
 
Upvote 0
thanks a lot Scott!!!! You are correct, I do not need <0 these cells are all formulas based off another sheet in the workbook, they will all either be 0 or > 0 ....so I just wanted to hide the rows with 0 before I printed these sheets...I will try you much simpler code as well...thanks a lot!

Bob

You made no reference to < 0 so I'm assuming that is not an option.

I believe your whole code could be reduced to this:

Code:
Sub test()
Dim x As Long, ws As Worksheet
For Each ws In Worksheets(Array("Batch 1", "Batch 2", "Batch 3", "Batch 4", "Batch 5", "Batch 6"))
    For x = 7 To 21
        ws.Rows(x).Hidden = (ws.Range("D" & x) = 0)
    Next x
Next ws
End Sub
 
Upvote 0
Hi Scott, I just tried your much better simpler code but got a type mismatch error for this
line:

ws.Rows(x).Hidden = (ws.Range("D" & x) = 0)

thanks a lot Scott!!!! You are correct, I do not need <0 these cells are all formulas based off another sheet in the workbook, they will all either be 0 or > 0 ....so I just wanted to hide the rows with 0 before I printed these sheets...I will try you much simpler code as well...thanks a lot!

Bob
 
Upvote 0
Scott's code works for me.

A few things to check:
- Make sure the sheet names listed in the array EXACTLY match your sheet names (check for any extra spaces or other characters that may lead to an inexact match, i.e. "Batch 1 " is not the same as "Batch 1"
- Make sure that you do not have any merged cells on your sheet
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,658
Latest member
GStorm

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