+ Reply to Thread
Results 1 to 9 of 9

How to fill an Array with values from Range of cells, skip cells then add more values.

  1. #1
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    How to fill an Array with values from Range of cells, skip cells then add more values.

    I have 2 workbooks, Array Source and Array Destination, right now the button (Create Purchase Request) in Array source will look at a the values in column R, and fill an Array (C to K) based on that value. Then insert that Array of Data into the Array Destination workbook. I would like to take the current Array of values but then skip columns and include column S in the Array. The Array destination workbook will get populated in columns C to K but then the added value from the S column will be in the X column. The code I that I am currently using is listed below.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: How to fill an Array with values from Range of cells, skip cells then add more values.

    Can you explain what are you trying to do?
    You want to copy some data from one sheet to another.
    Which part of data? What’s the criteria?
    Here’s an example on how to populate 2 range into 2 array.

    Please Login or Register  to view this content.
    Excel 2007 32 bit
    A
    B
    C
    D
    1
    name job unit
    2
    john a
    4
    3
    mark b
    5
    4
    rick a
    6
    5
    jane b
    7
    Sheet: Sheet1


    Excel 2007 32 bit
    A
    B
    C
    D
    E
    F
    1
    name job unit
    2
    john a
    4
    3
    rick a
    6
    Sheet: Sheet2

  3. #3
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: How to fill an Array with values from Range of cells, skip cells then add more values.

    Akuini, sorry I wasn't very clear. Array source has multiple rows of data (material to order), the user sets the Status (specifies if the data is "Ready to Order") in column R. The code looks for a value of Ready to Order and then takes the values from that Row Columns C to K and continues down the list of Ready to Order Data. They then press the "Create Purchase Request" button, once it transfers the data to the Array destination sheet, it changes the Status to "Requested" and enters a number into the Purchase Request Number field (column T). Thus allowing the user to track what they have requested and identify what request number it was requested on.

    The user also has the ability to set the status to "Return" if they want to send something back that is not actually needed. So if the user sets the status to "Return" the Purchase Request Number gets moved to column S (Line Item Comments - "Previously ordered on Purchase Request 2") and then the Purchase Request Number field for that row gets cleared. So when they press the "Create Purchase Request" button, the code also looks for a value of "Return" in column R and nothing in column T. If it finds the matching criteria, it transfers the item that is to be returned to the Array Destination sheet, then puts the new Purchase Request Number in the T column so that the next time they push the button it will not transfer that return request again. What I would like to be able to do is get the Line Item Comments transferred as well so that it is easier for the person who receives the Array Destination file to know that there is a line item that has to be Returned and not reordered, maybe even if the status says return, then then include that value in the array as well and transfer it to the correct column in the destination file.

  4. #4
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: How to fill an Array with values from Range of cells, skip cells then add more values.

    Your sample workbook has no data. Can you fill in some data so I can test the code.

  5. #5
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: How to fill an Array with values from Range of cells, skip cells then add more values.

    Attached is a copy of the Array Source workbook with some sample data. There are 11 rows that contain data. To test and see how the process works,
    1. Change the CreatePR Module to see the Array Destination workbook on your system - fpath = -
    2. Set 1 or More Line Item Status Fields to "Ready to Order" (you can press the Ready to Order Button to set the status of all the rows if you choose.)
    3. Press the Create Purchase Request Button
    For Testing purposes you do not need to save the Array Destination workbook. There is a save button on this file that we use to save an individual file based on fields in Rows 2:6.
    Every row that had a Line Item Status of "Ready to Order", will now be changed to "Requested". Also a number will be added to Purchase Request Number column and the PR# Field in Row 2.
    Close the Array Destination workbook
    4. Pick one or more of the rows of Data in the Array Source Workbook that says "Requested" in the Line Item Status column and change the status to "Return". Now the Purchase Request Number column for the rows that had the status changed to "Return", will be cleared out and the Line Item Comments column will say "Purchased on PR #". (if the Line Item Comments field had any comments previously, the old comment will be added to the "Purchased on PR #" statement).
    5. If you have any rows with a blank Line Item Status field, you can choose to set one or more to "Ready to Order" to include new items to be ordered along with the request to return items that are no longer wanted.
    6. Press the Create Purchase Request button. You will notice that there is nothing that identifies what lines are being returned, I would like to add the comments field to the array and possibly the Line Item Status if the status says "Return".
    Attached Files Attached Files
    Last edited by jrtraylor; 08-02-2017 at 11:12 AM.

  6. #6
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: How to fill an Array with values from Range of cells, skip cells then add more values.

    It’s a bit hard to follow, but I think I got the point.
    Among other things, basically you need to update information in comments field & Line Item Status (in Array Destination) if there is changed in Line Item Status (in Array Source) from "Requested" to “Return”. Am I correct?
    Note: Actually I can’t open ‘Array Destination.xlsm’ with ‘Workbooks.Open(fpath)’. I did adjust the path, still didn’t work, maybe because there are hyperlink that can’t be opened. So I open the file

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: How to fill an Array with values from Range of cells, skip cells then add more values.

    Note: Actually I can’t open ‘Array Destination.xlsm’ with ‘Workbooks.Open(fpath)’. I did adjust the path, still didn’t work, maybe because there are hyperlink that can’t be opened. So I open the file manually & adjust the code to activate it. So you need to keep ‘Array Destination.xlsm’ open to try the code below:

    Sorry wrong workbook, use this one:
    Attached Files Attached Files
    Last edited by Akuini; 08-03-2017 at 02:38 AM.

  8. #8
    Forum Contributor
    Join Date
    04-15-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2016 / Office 365
    Posts
    115

    Re: How to fill an Array with values from Range of cells, skip cells then add more values.

    Thanks for the help, I had to make a couple small modifications related to the comments and purchase request number fields and add a catch if someone presses the button and they don't have anything marked as "Ready to Order" or "Return" and it is working great. I was wondering if you would be able to help me better understand and identify what is going on in your code between With ws1 - End With, so that I can get better with VBA.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jrtraylor; 08-03-2017 at 01:22 PM.

  9. #9
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: How to fill an Array with values from Range of cells, skip cells then add more values.

    Ok, glad you figured it out.
    Sorry, I’m not good at explaining things, partly because English isn’t my native language. So you may read this link about With ..End With.
    https://docs.microsoft.com/en-us/dot...with-statement

+ 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: 1
    Last Post: 07-08-2017, 01:41 PM
  2. Skip x cells and fill (Fill/create weekly average from 7 days and fill down)
    By tunafishes in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-18-2016, 03:43 AM
  3. Replies: 2
    Last Post: 05-21-2014, 02:11 PM
  4. Using Range / Array to fill a set of cells
    By penfold1992 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2013, 10:14 AM
  5. Replies: 1
    Last Post: 04-11-2013, 01:02 PM
  6. [SOLVED] Skip loop if cells equal same values
    By adam2308 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-02-2012, 01:19 PM
  7. VBA Average Cells Skip Null Values
    By nguyeda in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-02-2011, 07:46 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