+ Reply to Thread
Results 1 to 11 of 11

Pasting a big range of values from an arraylist to a worksheet

  1. #1
    Registered User
    Join Date
    05-25-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Pasting a big range of values from an arraylist to a worksheet

    Hi,

    I have been cracking my head trying to figure this out. I'm trying to create a function that will fill 8 columns and an unspecified number of rows in a spreadsheet with data from an arraylist. Basically each column has a different heading and will contain different data and the number of rows will be different depending on the parameters passed. I will be determining the number of rows from the length of another arraylist

    To start, I read that we could initialize our arraylist without setting its size. I did this.
    Dim ArrayValues() As String

    Then, after finding the number of rows I will have from my data, I redimensionalized it as such
    ReDim ArrayValues(2 To 51, 1 To 8)

    Is that even right? :'(

    This is just dummy data but this is essentially how I'm trying to fill the arraylist. I'm not even sure if this is working.
    Please Login or Register  to view this content.
    And for actually outputting these data onto the worksheet, I have met no luck. I've been using google like crazy to help me but to no avail. Mostly I find help for populating one column with data. What about 8 columns and a variable number of rows.

    HELP! I'm really stuck. Thank you in advance for your help!
    Last edited by Leith Ross; 05-26-2013 at 04:20 PM. Reason: Added Code Tags

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Pasting a big range of values from an arraylist to a worksheet

    Hi,

    This will paste your array into the worksheet:
    Please Login or Register  to view this content.
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

  3. #3
    Registered User
    Join Date
    05-25-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Pasting a big range of values from an arraylist to a worksheet

    Thanks for the reply. But unfortunately, it's still not working. The same thing happens, it only spits "account names" in Cell A1. Not even A2.

    Am I not initializing/referencing things properly? This is pretty much what I do at the start before looping through r.
    Please Login or Register  to view this content.
    Then here I loop through r from 2 to 51.
    Last edited by Leith Ross; 05-26-2013 at 05:22 PM. Reason: Added Code Tags

  4. #4
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Pasting a big range of values from an arraylist to a worksheet

    so, this works fine for me:
    Please Login or Register  to view this content.
    Please test this code in a blank workbook. There is maybe a mistake in filling the array, as you say you are resizing it with variable values. Remove "On error resume next" to find the codeline of problem then.

  5. #5
    Registered User
    Join Date
    05-25-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Pasting a big range of values from an arraylist to a worksheet

    I just tried it as a Sub and my code works fine thanks. But what I'm trying to do is have it as a function so that the users can just do =Make_Array(parameters here...) on the worksheet and it will populate.

    Is that possible? I'm not very familiar with making functions in vba.

  6. #6
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Pasting a big range of values from an arraylist to a worksheet

    Yes this is possible, what would you like to enter as parameters?, How should the array size calculated?, Where does the values come from?
    Right now you have only strings in the parameter list, how to make an array with that information?

  7. #7
    Registered User
    Join Date
    05-25-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Pasting a big range of values from an arraylist to a worksheet

    Most of the values that I put into the array above is just dummy data.

    Basically the function will take in 4 parameters as string: name, account type, date and quarter type. The company name and quarter type will be directly put into a column of the array (if you look at the code), the date will be split into the Month&day as well as the year and will also be in their own columns. A few of the parameters will be used to call other functions in vb.net to get the specific values like for the "type" and "account_name" columns. This vba function should essentially be pulling data out from arraylists given from the vb.net function.

    That's why I need the function. So that the user can just put in those parameters and have the worksheet populated with what they want. Any advice on how I can get this function to work would be awesome!

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Pasting a big range of values from an arraylist to a worksheet

    you cannot have a worksheet function populate cells other than the cell(s) that call the function. if you return an array the user has to array-enter the function into sufficient cells to contain the result array
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  9. #9
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Pasting a big range of values from an arraylist to a worksheet

    As an alternative you can enter the parameters into a userform which is opened by a shortcut, e.g.: Book1.xlsm
    Open the UserForm with Ctrl+D or the button on sheet1.

  10. #10
    Registered User
    Join Date
    05-25-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Pasting a big range of values from an arraylist to a worksheet

    Thanks for the input JosephP.

    Very interesting... So there isn't a way to populate the whole worksheet with just one function? so for example if my cells("A1:A15") need account names and cells ("B1:B15") need company IDs, etc, they would have to be done in separate functions?

    And tehneXus, thanks for your help. I assigned a button to my sub and it works well now. The only thing is that the users are looking to have it as a function in the long run.
    Last edited by chrissy92; 05-28-2013 at 09:41 AM.

  11. #11
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Pasting a big range of values from an arraylist to a worksheet

    You can achieve it with one function but that function must be array entered into all the output cells-or the function returns an array and you pass indices to it with each call, like the INDEX function

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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