Hi Folks,

I got some help from @ByteMarks on some code that would hide rows in various places in my spreadsheet depending on the value of a reference cell. My spreadsheet uses a main "Input" page to add information about a shipment of goods, and then a bunch of shipping documents are created (in other tabs) based on that information. The pages are then converted to PDF and sent to me via email. The code I'm trying to fix (that I obtained from this forum) hides rows in the other tabs where the shipping documents are created, with the express purpose of shortening the size of the document; ex: If I'm shipping 14x goods, there are 14 rows of data in these tabs; if I'm only shipping 2x goods, all rows but 2 are hidden to shorten the size of the PDF when it's printed.

Here is the code, and where in the code the error is happening when I try to run it in my spreadsheet:

Sub AdjustRows(NumGoods As Integer)
a = Array("CI_HIDE", "PL_HIDE1", "PL_HIDE2", "PL_HIDE3", "SR_HIDE", "SR_HIDE1", "SR_HIDE2", "SR_HIDE3", "SR_HIDE4", "CC_HIDE", "CC_HIDE1", "CC_HIDE2", "CC_HIDE3", "SBOL_HIDE", "AN_HIDE")
For i = 0 To UBound(a)
    With Range(a(i))
        .Rows.Hidden = False
        Select Case NumGoods
            Case 1 To 5
                r = NumGoods + 1
                .Rows(r & ":6").EntireRow.Hidden = True
        End Select
    End With
Next
End Sub
There is also the following private sub function for the "Input" tab where I have my reference cell:

Private Sub Worksheet_Change(ByVal Target As Range)
With Target
    If .Address = "$I$21" Then
        Select Case .Value
            Case 1 To 6
                Call AdjustRows(.Value)
        End Select
    End If
End With
End Sub


For reference, the reference cell I use is I21 (it was originally B2 when I attached the example spreadsheet for help with writing the code), which is where I enter the # of goods being shipped. I'm not sure what the "With Range(a(i)) refers to, though I'm guessing I need to adjust this in some way to allow it to work?