+ Reply to Thread
Results 1 to 2 of 2

VBA copy value from array to another array - Type mismatch error

  1. #1
    Registered User
    Join Date
    04-30-2019
    Location
    San Diego, CA
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2

    VBA copy value from array to another array - Type mismatch error

    Hello,

    I just noticed a mistake and thought I found the solution myself already (edits in red), but the same error pops up

    I need help with the following code.
    Please Login or Register  to view this content.
    screw_data_arr is an array that is created in another Sub (Public screw_data_arr As Variant) from a table in one of my worksheets.
    It consists of 75 rows and 5 columns.
    Column 1 contains different bolt thread sizes, column 2 the respective threads per inch for that thread size (also referred to as "pitch").
    So, in my example, if I search for the thread size of 3, it should write all the thread pitch values (4,8,12) for that thread size into the array pitch_arr
    Upon executing the code, I get a Type mismatch error inside the If statement.

    See the example table below:

    Size Pitch
    2.5 4
    2.5 8
    2.625 12
    2.75 4
    2.75 8
    2.875 12
    3 4
    3 8
    3 12
    Last edited by gargantuLars; 04-30-2019 at 01:02 PM.

  2. #2
    Registered User
    Join Date
    04-30-2019
    Location
    San Diego, CA
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    2

    Re: VBA copy value from array to another array - Type mismatch error

    Never mind. I changed the array declaration as follows: Dim pitch_arr(1 To 3) As Variant.
    Now it works.
    However, how would I do it if I wanted a dynamic array of unknown size?

    Edit//
    Found a solution with ReDim Preserve
    Last edited by gargantuLars; 04-30-2019 at 01:27 PM.

+ 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. can't resolve type mismatch error related to an array
    By dschmitt in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-02-2018, 07:54 AM
  2. Type Mismatch Error with Array
    By Microsoft Excel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2014, 02:11 PM
  3. [SOLVED] type mismatch error when trying to populate array
    By neek13 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-21-2013, 03:35 PM
  4. Multi-Level Array Type Mismatch Error
    By CrazyFileMaker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-04-2009, 06:20 PM
  5. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2005, 01:54 AM
  6. Array problem: Key words-Variant Array, single-element, type mismatch error
    By davidm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2005, 12:30 AM
  7. [SOLVED] Help: Compile error: type mismatch: array or user defined type expected
    By lvcha.gouqizi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2005, 05:05 PM

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