+ Reply to Thread
Results 1 to 6 of 6

copy from sheet to array

  1. #1
    Registered User
    Join Date
    05-15-2016
    Location
    Sydney
    MS-Off Ver
    excel 2013
    Posts
    21

    copy from sheet to array

    Hi i have an excel data(mix of strings and integers and doubles) that i copy into a variant as below

    Dim arr as variant
    arr = Sheets("sheet1").range("A1:I20").value

    The problem with the above is that it is rounding up the double values into the array. so if i have something like 1.10..it is it putting the value 1.1 in the array.

    I need it to copy the EXACT values without any rounding up etc..

    I am happy for it to copy all values as string.

    but when i try the below i get the mismatch error


    Dim Arr() As String
    Arr = ActiveWorkbook.Worksheets("Sheet1").Range("A1:I20").Value

    Can someone please advise? Thanks heaps.
    Last edited by twozedz; 08-14-2016 at 05:26 AM.

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: copy from sheet to array

    Hi,

    If you need to use the data exactly as displayed, you will need to loop through the cells and read the Text property rather than the value (because 1.10 is the same number as 1.1 after all).
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    05-15-2016
    Location
    Sydney
    MS-Off Ver
    excel 2013
    Posts
    21

    Re: copy from sheet to array

    that will affect the performance though. I have a lot of arrays to work with. Is there a quicker way to loop through each cell. i would prefer avoiding traffic between worksheet and array as much as possible
    Last edited by twozedz; 08-14-2016 at 05:27 AM.

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: copy from sheet to array

    No there is not.

  5. #5
    Registered User
    Join Date
    05-15-2016
    Location
    Sydney
    MS-Off Ver
    excel 2013
    Posts
    21

    Re: copy from sheet to array

    sorry after reassessing the code i have realised the value 1.1 instead of 1.10 is returning from a node in an xml file. i want 1.10 to be displayed not 1.1

  6. #6
    Registered User
    Join Date
    05-15-2016
    Location
    Sydney
    MS-Off Ver
    excel 2013
    Posts
    21

    Re: copy from sheet to array

    ok i have figured out the issue.

    the xml double figures are going into a variant and the variant is storing them after they get rounded or the variant is rounding them. not sure which one.

    converting the xml values to string values before they go into the variant is the solution to the issue.

    thanks, cheers

+ 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. How to copy an array to excel sheet?
    By helpmeimlost in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2014, 02:24 AM
  2. [SOLVED] Macro to use array to copy all rows to a new sheet if a cell is not blank not working
    By capson in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-05-2014, 01:13 AM
  3. Replies: 0
    Last Post: 06-28-2014, 02:26 PM
  4. Replies: 3
    Last Post: 05-06-2014, 01:32 AM
  5. copy entire excell sheet cells values into string array
    By laltoo2405 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2014, 09:17 PM
  6. Copy value to Array variables use them in another sheet!
    By ravikiran in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2012, 04:15 AM
  7. Copy from one sheet using an array
    By peakymatt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2009, 09:23 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