+ Reply to Thread
Results 1 to 12 of 12

Unable to Transfer Array Contents to Worksheet Range

  1. #1
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Unable to Transfer Array Contents to Worksheet Range

    Hello. I am unable to identify a solution to a type mismatch error I receive in the line of code below. Have tried several variations, but with no success.

    The objective of the code is to use search criteria to identify specific rows of data in a table based on the contents in one of the columns; capture those rows and specific columns of data in an array; then transfer that data to a specific range. This is done in a loop until all qualifying items have been processed. The array and output must be able to handle single and multiple records.

    I could not paste the code just prior to this, as it contains characters that the system won't let post. So I've included a working example file. Any help in diagnosing is much appreciated!!

    Please Login or Register  to view this content.
    Last edited by Matt W; 09-15-2021 at 10:56 PM.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Unable to Transfer Array Contents to Worksheet Range


    Hello,

    the error occurs 'cause the variable g is empty ! Easy to check … So you must revise the logic used …

  3. #3
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Unable to Transfer Array Contents to Worksheet Range

    Quote Originally Posted by Marc L View Post

    Hello,

    the error occurs 'cause the variable g is empty ! Easy to check … So you must revise the logic used …
    Thank you, Marc. I have sourced the problem in the logic and made the correction to solve the error. However, the objective of the code is to transfer the rows of data captured in the array (g) to the target range (GroupListImportRange) on the worksheet. However, only 1 row from the array is being transferred to the target range. There should be two rows transferred in the sample file. I do not know what changes I need to make to capture and transfer the complete set of data rows, rather than just one. Thanks for any assistance you can provide. I have included an updated file with the correction.

  4. #4
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Unable to Transfer Array Contents to Worksheet Range

    Sample file attached.
    Last edited by Matt W; 09-16-2021 at 11:54 PM.

  5. #5
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Unable to Transfer Array Contents to Worksheet Range

    g never gets populated, I stepped through your code

  6. #6
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Unable to Transfer Array Contents to Worksheet Range

    Okay, I have taken steps to get the array populated, and have verified that it populates correctly (multiple rows of 29 columns of data in this case). However, the problem is in the transfer of the array contents to the target worksheet range. When there are multiple rows (>1) in the array to loop through, the transfer to the target worksheet range works as intended. But when there is only 1 row, then it fails (it puts only the item from the first column of the array into all the columns in the target range). I believe the problem is in the last line of code below; I have tried multiple iterations, but without success. The code needs to be able to handle one or many rows. Any help is greatly appreciated!

    Please Login or Register  to view this content.
    * Had to remove code for the Filter (...) function, since Sucuri reports malicious code

    Sample file attached
    Last edited by Matt W; 09-22-2021 at 12:18 PM.

  7. #7
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Unable to Transfer Array Contents to Worksheet Range

    If there is only record row to copy when the error occurs, why is your array g filled with 2 records?? Check in immediate screen when code stops

  8. #8
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Unable to Transfer Array Contents to Worksheet Range

    Quote Originally Posted by nigelog View Post
    If there is only record row to copy when the error occurs, why is your array g filled with 2 records?? Check in immediate screen when code stops

    Array g works fine and is filled correctly with two records; those two records make up the Group record being processed from array b, and there will always be at least two records in g (it takes two to create a group).

    Array b (as reflected in the code above) is the one that may only contain one record (there may only be one Group), or it may need to contain multiple Groups. The code works fine when array b contains more than one record, but fails when there is only one record.

    The result of the failure is evidenced during transfer of the record from array b to the target range ("GroupImportRange")(it puts only the item from the first column of array b into all the worksheet columns in the target range).

    Hope this helps clarify.

  9. #9
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Unable to Transfer Array Contents to Worksheet Range

    Second element of the array "b" is a "Null" value, is that the cause??

  10. #10
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Unable to Transfer Array Contents to Worksheet Range

    Good question. But no, null values in array b are text strings inserted into unused fields for a Group record. You will see them in the source table. Again, everything processes as intended when there are multiple records in array b to loop through. I think it has to do with how to populate an array when there is only one item vs multiple items; and how transfer the record(s) out of the array when there is only one item vs. multiple items. Somehow I need to accommodate both, but so far have failed. I thought the below would solve for this, but it doesn't work either.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Unable to Transfer Array Contents to Worksheet Range

    Still needing some serious assistance here. Have tried the changes in red below. The code will process without error, but does not function properly. When array b contains only one one row, the transfer of that row of 29 columns to the target range results in the data element of the first column in the array being transferred to ALL the columns of the target range. This does not happen when array b contains more than one row to loop through. Any help is much appreciated.


    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Unable to Transfer Array Contents to Worksheet Range

    Still in need of help on this. Can anyone assist?

+ 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. Replies: 9
    Last Post: 05-08-2018, 12:31 PM
  2. Replies: 10
    Last Post: 09-22-2017, 02:48 PM
  3. [SOLVED] Unable to convert array to range while performing Autofilter
    By sreeks in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2016, 01:12 AM
  4. Unable to set Formula Array property of the range class
    By Chippi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-10-2014, 03:41 PM
  5. How to insert array contents into worksheet between columns 1 and 2 on wrkshet
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2011, 11:52 AM
  6. Dump contents of multidimensional array to worksheet
    By gnome_core in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2009, 04:44 PM
  7. Transfer Array values to a range and Vice Versa
    By danny2000 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2008, 09:22 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