+ Reply to Thread
Results 1 to 15 of 15

Filling array with several values and extent array using these values

  1. #1
    Registered User
    Join Date
    02-02-2013
    Location
    NL
    MS-Off Ver
    Excel 2010
    Posts
    63

    Filling array with several values and extent array using these values

    Hi all,

    I have values which are used to fill an array. Each value is related to a column and row.

    The values are:

    12 (R1C1)
    28 (R2C2)
    35 (R3C3)
    ... (R4C4)
    ... (R5C5)
    ... (R..C..)

    So the numbers are diagonally put into the array and adjacent values (left and right depending on in which column the above value is located) need to be calculated using a user defined interval (10), resulting in the below array:

    12, 22, 32, ...
    18, 28, 38, ...
    15, 25, 35, ...
    ..., ..., ..., ...

    Can someone help me with this and its VBA code? The number of values will most likely be extended to 20. Hence, an array of 20 x 20 will be required.

    Regards,
    Martijn

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Filling array with several values and extent array using these values

    How are you currently populating the array?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-02-2013
    Location
    NL
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Filling array with several values and extent array using these values

    I tried this, and it allows me to populate the array diagonally but then I get stuck with calculating the remaining values.
    Please take notice, that due to the my inexperience with VBA code and arrays like this, I started with only 3 values.

    Please Login or Register  to view this content.
    For populating the remainder of the array I tried where Ival is the interval (10) and "l" (a counter to multiply the interval value every time the loop is restarted). But this does not work properly.

    Please Login or Register  to view this content.
    Any suggestions? I must be way off most likely .

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Filling array with several values and extent array using these values

    Perhaps.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-02-2013
    Location
    NL
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Filling array with several values and extent array using these values

    Norie,

    Thanks! That works like I needed. However, how do you get values from cells to an array like you used for arrStart?

    I have 20 values which are in one row, but different adjacent cells. Is there some way of populating arrStart using these values?

    Thanks, Martijn

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Filling array with several values and extent array using these values

    Martijn

    Thought you might ask something like that.

    Where are the values located on the worksheet?

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

  7. #7
    Registered User
    Join Date
    02-02-2013
    Location
    NL
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Filling array with several values and extent array using these values

    Hi Norie,

    Here it is .


    Example.xlsm

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Filling array with several values and extent array using these values

    Try this.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-18-2015
    Location
    Lisbon, Portugal
    MS-Off Ver
    2010
    Posts
    38

    Re: Filling array with several values and extent array using these values

    Greetings,

    I was suggesting this:

    Please Login or Register  to view this content.
    But Norie's code should be faster rather then using a loop (right Norie?)

    Regards,
    Daniel

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Filling array with several values and extent array using these values

    Daniel

    My code uses 2 loops.

  11. #11
    Registered User
    Join Date
    10-18-2015
    Location
    Lisbon, Portugal
    MS-Off Ver
    2010
    Posts
    38

    Re: Filling array with several values and extent array using these values

    Quote Originally Posted by dafer660 View Post
    Greetings,

    I was suggesting this:

    Please Login or Register  to view this content.
    But Norie's code should be faster rather then using a loop (right Norie?)

    Regards,
    Daniel
    This loop was meant to "map" the array but your way is cleaner.

  12. #12
    Registered User
    Join Date
    02-02-2013
    Location
    NL
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Filling array with several values and extent array using these values

    Norie, Daniel,

    Thanks for your help! It works perfectly. I have another question, which is an extension of the code.

    Once the numbers, as the previous code does, are generated, the numbers need to be included in a listing which is based on an user defined interpolation interval
    between a minimum and maximum value. In the attached file I took an example interval of 1.5 m and 3 listings for column 1 to 3. However, a total of 20 columns can be populated depending on the user input. The red marked cells show the location where the value from the results of each column are to be included. This means that part of the second table need to be shifted down each time a value is included. Can you help me with this?

    Many thanks in advance,
    Martijn


    Example 2.xlsm

  13. #13
    Registered User
    Join Date
    02-02-2013
    Location
    NL
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Filling array with several values and extent array using these values

    I have been trying to solve, also because I want to learn, the problem myself and came to the following (based on Example 2):

    Please Login or Register  to view this content.
    However, although it presents the values from the generated array in the correct sequence (left to right, top to bottom), each time a value is copied from the array into the column, it generates a new row first. Hence, 3 values result in 3 rows instead of just one. What am I doing wrong?

    Capture.JPG


    Regards,
    Martijn
    Last edited by Martijn79; 12-30-2015 at 05:41 AM. Reason: Snapshot of the sheet included

  14. #14
    Registered User
    Join Date
    02-02-2013
    Location
    NL
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Filling array with several values and extent array using these values

    Hi Norie, Daniel,

    I have found a solution, but I am not sure if this is the cleanest solution. Can you give me advise?

    Please Login or Register  to view this content.
    Thanks in advance,
    Martijn

  15. #15
    Registered User
    Join Date
    02-02-2013
    Location
    NL
    MS-Off Ver
    Excel 2010
    Posts
    63

    Re: Filling array with several values and extent array using these values

    For some reason my code does not function if I adjust the sheet input values. See example 3.


    Example 3.xlsm

    Help would be much appreciated!

+ 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. Pull sub array from array using multiple column_num values
    By SinJinQLB in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-25-2015, 05:37 PM
  2. Create an array based off values in another array - exclude blanks
    By clifton1230 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-05-2013, 05:35 PM
  3. Replies: 19
    Last Post: 05-09-2012, 03:31 AM
  4. Find a value in an array and return multiple values in an adjacent array
    By tonbra in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2012, 08:35 PM
  5. Does filling part of an array from a range re-dimension the array?
    By barryleajo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-04-2011, 10:09 AM
  6. String array values to array of User-Defined Types
    By rtiltins in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-03-2008, 07:45 AM
  7. [SOLVED] Filling Source Data Array with Decimal Values
    By John Michl in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 03-22-2006, 12:20 PM

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