Ive got the same error as Tiago, Run-time error '9': Subscript out of r

  • Dan Bird
    Asked on May 24, 2021 at 2:09 PM

    Ive got the same error as Tiago, Run-time error '9':
    Subscript out of range..
    Any thing that will help please?

  • Alexander_G
    Replied on May 24, 2021 at 5:14 PM

    Hello, 👋

    Thanks for contacting JotForm Support.

    Kindly, double-check if you have the same name for the table from the 1.4 step and the code you entered on the step 2.7:

    1.4: Change the name of the table in the Table Design tab to something meaningful. (We used the name “MyTable” for the purpose of this walkthrough.)

    2.7: Double-click the text box to open the Visual Basic module. In the blank space between the “Private Sub” and “End Sub” strings, enter the macro text below — be sure to replace any references to “MyTable” and “A3” with your table name and text box cell, respectively.

    ‘Filter Name field in MyTable Table.    
    Dim strFilter As String
    strFilter = “*” & [A3] & “*”    
    Debug.Print strFilter
    ActiveSheet.ListObjects(“MyTable”).Range.AutoFilter _
    Field:=1, _
    Criteria1:=strFilter, _
    Operator:=xlFilterValues


    Thanks,

    Alex

  • Evan Morris
    Replied on June 22, 2021 at 12:16 AM

    I got the same error message as the last two people (Run-time error 9). I'm running it on Excel for Microsoft 365.

    SOLUTION:

    Turns out, the actual code itself is fine. The run-time 9 error is a result of copying and pasting the code. More specifically, it's the inverted commas/quotation marks (i.e. " ") that are causing the issue. 

    I ran a test on a very small spreadsheet, by creating 20 rows and 5 columns of data. I followed the instructions to the letter, however, I realised something wasn't quite right when the 2 comment lines in the code ('Clear MyTable custom filter) and ('Filter Name field in MyTable Table.) were red in the VBA editor. They should be green, meaning they're a comment. As soon as I removed the ' symbol, and replaced it by directly typing it in, the VBA editor recognised that line as a comment. 

    I then went through the code and removed each inverted comma symbol (i.e. " ") and replaced it with new ones by directly typing them in. 

    As soon as I did that, the code worked perfectly and I could search my data.
    It appears as though there may be some type of font issue when copying/pasting the code from the website.

    ADDITIONAL:

    I also tried shrinking my table identifier (i.e. MyTable) to one column, instead of all 5 columns. This worked a treat and enabled me to only search for a name in one column. 

    Cheers,