+ Reply to Thread
Results 1 to 3 of 3

Help in storing values to an array

  1. #1
    Registered User
    Join Date
    02-22-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    25

    Help in storing values to an array

    Hi all, I'm trying to learn more stuff about macro excel by trying how to store values into an array. I tried this website and decided to copy and paste this chunk of code to see how he/she stored his values into an array:

    Please Login or Register  to view this content.
    However he has this "Type mismatch error" at this code " dCellValues(iRow) = Cells(iRow, 1).Value"

    I have no idea why he got this error, I tried to replace the code with "Range("A", iRow).Value" but it still yields the same error.

    Please help, I tried to look for another source to learn array stuff in macro excel, but couldn't find any simple codes that I can understand easily. You could also help me by giving me some nice links for tutorials:D Thank you xD

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help in storing values to an array

    hi, crisshinn, error "Type mismatch error" usually means that you trying figuratively to sum 2 apples and 1 litre of water. In your case your array can hold only data of Double data type:
    Please Login or Register  to view this content.
    and you are trying to force it to hold something else (String data or Integer etc.). Check value of Cells(iRow, 1)

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,604

    Re: Help in storing values to an array

    Therefore Dim dCellValues() As Variant.
    Note 1: syntax error: Range("A", iRow).Value should be Range("A" & iRow).Value, not comma iRow

    Note 2: Integer variables are stored as 16-bit (2-byte) numbers ranging in value from -32,768 to 32,767.

    Since the sheet can have greater than one million rows, you need the Long type vs. Integer:
    Long (long integer) variables are stored as signed 32-bit (4-byte) numbers ranging in value from -2,147,483,648 to 2,147,483,647.
    Ben Van Johnson

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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