+ Reply to Thread
Results 1 to 7 of 7

Assign values to 2D dynamic arrays

  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,116

    Assign values to 2D dynamic arrays

    Hello,

    I have a simple VBA question.

    For each 'Y' or 'Yes' values found in column C, I'd like to add its corresponding row values (column A and column B) to a 2D array.

    Therefore I need it to be dynamic "row" wise, but column wise it's fixed to 2 columns.

    How do I do it?

    Note here that screenshot of column A and Column B is a dynamic array (in other words A2# = A2:B9). Column C is where user input will be

    Given the print screen below, I'd like my result:
    arr(1,1) = B
    arr(1,2) = Ran2
    arr(2,1) = D
    arr(2,2) = Ran4

    Please Login or Register  to view this content.
    2D Dynamic Array VBA.png
    Last edited by dluhut; 06-19-2024 at 09:38 AM.

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

    Re: Assign values to 2D dynamic arrays

    One way...
    Please Login or Register  to view this content.
    Last edited by Sintek; 06-19-2024 at 09:44 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!!!

  3. #3
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,116

    Re: Assign values to 2D dynamic arrays

    @Sintek...thanks for the help.

    Quick question. In your code, you used a filter and looked for "Y"

    What happenend if user input 'Yes', 'yEs', 'y', 'Y' etc?

    That's the reason why I'm doing a loop and check via UCASE for both 'YES' and 'Y'.

    Can FILTER be able to do check with UCase of values?

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

    Re: Assign values to 2D dynamic arrays

    works for all...

  5. #5
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,116

    Re: Assign values to 2D dynamic arrays

    Sorry...am not really an expert in VBA.

    Tried changing

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    But got a Run-time error 13 Type mismatch error in

    data = Filter(Evaluate("Transpose(If(Left(" & .Columns(3).Address & ",1)=""Y"", row(1:" & Rows.Count & ")))"), False, 0)

  6. #6
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,116

    Re: Assign values to 2D dynamic arrays

    Solved and reps up to @Sintek

    Change a little of your code to

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Assign values to 2D dynamic arrays

    Please Login or Register  to view this content.

+ 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] compare dynamic arrays, return missing values
    By guillaume0314 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-09-2023, 03:30 AM
  2. [SOLVED] sum values, each row, dynamic arrays, return spilling column
    By guillaume0314 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-16-2023, 12:53 PM
  3. [SOLVED] map values dynamic arrays
    By guillaume0314 in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 06-08-2023, 05:45 PM
  4. [SOLVED] matching values 2 dynamic arrays
    By guillaume0314 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-30-2022, 01:00 PM
  5. [SOLVED] Sum values based on variable criteria [dynamic arrays]
    By scrin in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 08-02-2021, 09:06 PM
  6. [SOLVED] Efficient VBA method for looking up cell values - dynamic sheet references and arrays
    By phor89 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2021, 01:04 PM
  7. Replies: 2
    Last Post: 08-26-2013, 01:27 AM

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