+ Reply to Thread
Results 1 to 4 of 4

Compile error: Expected Array

Hybrid View

  1. #1
    Registered User
    Join Date
    02-20-2024
    Location
    Administrative District, Belobog
    MS-Off Ver
    Office 365
    Posts
    2

    Compile error: Expected Array

    Hi everyone,

    I have been getting the same error when attempting this course assignment as mentioned in the thread title above. The assignment objective is to create a subroutine that allows the user to select the Identifier from a drop-down menu in cell F2 and the Key from a drop-down menu in cell F3 (these drop-down/data validation menus are already available in the starter file) and any rows of the data (columns A, B, and C) whose Batch ID meets those criteria will be highlighted GREEN.

    I've attached a screenshot of the Excel file for reference:
    Screenshot 2024-02-20 200654.png

    My own written code so far are as below;
    Screenshot 2024-02-20 201256.png

    with Identifier & Key already provided in the code as below:
    Screenshot 2024-02-20 201426.png

    From what I understand, the code I've written should be able to highlight the Batch ID following the Identifier at the first letter and the Key at the number after the hyphen (e.g. "T3-238L" - Identifier: T, Key: 2), but I keep getting the compile error: Expected Array when running the code.

    So far, I've tried doing several things to troubleshoot my code:
    • removing 'identifier As String' from the Dim line of the code, but it still came up with the same error
    • Replacing 'identifier(ID)' and 'key(ID)' by just 'ID'; but that just skips the For... Next loop completely.
    • I've tried using 'Range("A2:A")" for the If statement line, but still the same error (I know that this might be wrong in the first place, but it was worth a shot)

    I'm new to Excel/VBA programming and to this forum as well, and also would like to ask for help in identifying what what missing from my code. I'll really appreciate any help from everyone on this forum. Thanks!

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,927

    Re: Compile error: Expected Array

    removing 'identifier As String' from the Dim line of the code, but it still came up with the same error
    You also need to remove key
    Neither of those variables are used and are named the same as the functions.

  3. #3
    Registered User
    Join Date
    02-20-2024
    Location
    Administrative District, Belobog
    MS-Off Ver
    Office 365
    Posts
    2

    Re: Compile error: Expected Array

    Thanks for the reply, ByteMarks and sintek!

    And now my code is finally able to run!

    Thanks again!

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,955

    Re: Compile error: Expected Array

    Or you can do...
    T2-3


    Sub J3v16()
    Dim Ele As Range
    For Each Ele In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        If Left(Ele, 1) = Range("identifier") And Val(Mid(Ele, 4, 1)) = Range("key") Then
            Range("A" & Ele.Row).Resize(, 3).Interior.ColorIndex = 4
        End If
    Next Ele
    End Sub
    Last edited by Sintek; 02-20-2024 at 09:15 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] compile error: expected array ; binomial asset pricer
    By fruitloop44 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-29-2022, 06:07 PM
  2. Replies: 0
    Last Post: 08-09-2017, 07:06 AM
  3. [SOLVED] Compile error: Expected Array
    By jkj115 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-27-2016, 03:01 PM
  4. [SOLVED] Compile error: expected array
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2015, 04:06 AM
  5. [SOLVED] Help with Compile Error: Expected Array
    By g8r777 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2012, 11:44 AM
  6. Compile Error: Expected Array
    By abfrempong in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-13-2012, 02:35 AM
  7. Compile Error - Expected Array
    By AccountantCost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2009, 02:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1