+ Reply to Thread
Results 1 to 20 of 20

How to code it with array ?

  1. #1
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    How to code it with array ?

    To be honest, I always have my headache for array coding,
    even after I've tried to learn it again and again by reading the internet.

    Case:
    The user type a transaction in input area
    click InputToData button
    then the macro put the data in data area

    Before I write the macro, I make a preparation by making a template range, which looks like image below :
    2021-02-22_16-16-35.gif

    The code I wrote :
    Please Login or Register  to view this content.
    The code works as expected. There's no problem.

    The problem is :
    Now I've been thinking on how to do the code using array without the need to make a template.
    So, there's no template area (the yellow one), and hoping the code lines will be fewer.

    Again, I'm totally lost if it's about array.

    Any kind of help would be greatly appreciated.
    Thank you in advanced.
    Attached Files Attached Files
    Last edited by karmapala; 02-22-2021 at 04:24 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: How to code it with array ?

    what about
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: How to code it with array ?

    And for the yellow area
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: How to code it with array ?

    Not sure if this will help, but it sources info from green input area

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: How to code it with array ?

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

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: How to code it with array ?

    Please try

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

  7. #7
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: How to code it with array ?

    The results are in a new sheet 'Sheet2'.
    Please Login or Register  to view this content.
    Best Regards,
    Maras.

  8. #8
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: How to code it with array ?

    Thank you for everyone who donate the code for me.
    I've tried each of them. But I am very very sorry that I forget to mention these :

    1. The input area will always change based on when any transaction happen.
    For example, the next time input is 21 Feb 2021 (still the same day)
    but the name is Xena, the ID is BZ, the item are Apple 3, Orange 10, Avocado 2...
    next time, the name is Boboho, the ID is BX, the item are Chicken 20,
    and so on.

    Tomorrow, the date for surely is 22 Feb 2021...
    but the name, the ID and the how many rows of item name never fix.

    2. The data area (the blue header) is already manually created before (not created by the code).
    the row value below the header is the one which will be created by the code,
    and the row will grow because the data from the input area will always be put to the last blank row available of column DATE each time the user click the "input" button.

    3. actually there is a last line for the "input" button code
    which clearcontents the value of the name, the ID, the item and the val in the input area.
    (the Date column in the input area has a "=today()" formula).

    Again, I'm very sorry that I forget to mention about that.

    So....
    @maniacb,
    please have a look if your modified code is OK :

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

    @jindon,
    I'm very sorry as I don't know on how to modify the code.
    .
    .
    .

    @Bo_Ry,
    please have a look if your modified code is OK :

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

    @maras,
    please have a look if your modified code is OK :
    Please Login or Register  to view this content.
    .
    .
    .

    @mohadin,
    I'm sorry I can't use the code, because it seems that your code still use the "template" range.

    Thank you for all once again.
    Last edited by karmapala; 02-22-2021 at 08:06 AM.

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: How to code it with array ?

    I don't understand what you are trying to say.

    My code is flexible of the changes in Input area as long as the first part is in [A1:B5] and the 2nd part is in one block of range after A6.
    And my code generates header from the 1st and 2nd range.

    Are you saying the number of rows in 1st part may change as well?

  10. #10
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: How to code it with array ?

    Ahhh
    I see
    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: How to code it with array ?

    Not sure I understand everything, but try...
    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: How to code it with array ?

    Quote Originally Posted by jindon View Post
    I don't understand what you are trying to say.

    My code is flexible of the changes in Input area as long as the first part is in [A1:B5] and the 2nd part is in one block of range after A6.
    What I mean is, the input area is something like a user form.
    The first condition (before the user type a value) is :
    Date : ...
    Name : ...
    ID : ...

    ITEM VAL
    ... ...
    ... ...
    ... ...
    available until 10 rows.
    (all those ... are empty cells)


    And my code generates header from the 1st and 2nd range.
    Before running the code, the header already created manually, jindon.
    So, there is already the blue header before running the code.

    Are you saying the number of rows in 1st part may change as well?
    Yes, the number of rows for Item/Val may change all the time, depends on how the transaction happen.

    For example:
    today at 10 am, John buy 5 items with their respective quantity as seen in the example.
    the user input it in the "user form" (input area).
    So, the number of non-empty rows under Item/Val here is 5 rows.
    Then the user click the button.
    the code put/move the value (which the user input in the "user form")
    to the last blank row of the blue header column DATE,
    then clear the value in the "user form" which user just typed it before.

    next, at 10.30 am, Xena buy 2 items : book 2 pcs, glass 1 pcs.
    the user input it in the "user form" (input area).
    So, the number of non-empty rows under Item/Val here is 2 rows.
    Then the user click the button.
    the code put/move the value (which the user input in the "user form")
    to the last blank row of the blue header column DATE,
    then clear the value in the "user form" which user just typed it before.

    and so on.

    That's why in my code (using the template),
    I always count first to get how many non-empty rows are there under Item/Val of the "user form",
    after I have the count, I use this to set the range of the template to be "copied".

    I hope I am clearer now.
    Thank you jindon.
    Last edited by karmapala; 02-22-2021 at 08:55 AM.

  13. #13
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: How to code it with array ?

    Then
    Try this version



    [UPDATED]
    Please Login or Register  to view this content.
    Last edited by mohadin; 02-22-2021 at 08:47 AM.

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: How to code it with array ?

    Have you really tried?
    Attached Files Attached Files

  15. #15
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: How to code it with array ?

    Quote Originally Posted by maras_mak View Post
    Not sure I understand everything, but try...
    Thank you, maras.

    Your first code in reply #7 actually works after the "making of the header" code line is deleted,
    and in "With .[a1].Resize(UBound(a2))", the [a1] is change to be always the last blank row.

    The code from you which I modify (in post #8) has exactly the same result with your code in post #11.

    Thank you maras_mak.

  16. #16
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: How to code it with array ?

    Quote Originally Posted by mohadin View Post
    Ahhh
    I see
    I am sorry, as it still doesn't give me the expected result, mohadin.

    Anyway, thank you for your help.

  17. #17
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: How to code it with array ?

    I am very sorry as I'm limited in English, I can't express what I mean correctly.
    Below is a sample condition :

    01.png
    1. The green area (input form) has no value
    2. the blue header has already one row of data

    .
    .
    .

    02.png
    After the user type the value in the input form (there are two kind of items)

    .
    .
    .

    03.png
    After the user click the button:
    1. The green area has no value again
    2. now the blue header has three rows of data
    where the last two rows of data are from what user typed before in the input form (green area)

    .
    .
    .

    Next, the user again input a value into the user form (there are four kind of items) :
    04.png

    .
    .
    .

    After the user click the button:
    05.png
    1. The green area has no value again
    2. now the blue header has seven rows of data
    where the last four rows of data are from what user typed before in the input form (green area)

    I hope my explanation is better now

  18. #18
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,514

    Re: How to code it with array ?

    Change to
    Please Login or Register  to view this content.
    Last edited by jindon; 02-22-2021 at 10:15 AM.

  19. #19
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: How to code it with array ?

    Please try

    Please Login or Register  to view this content.

  20. #20
    Valued Forum Contributor
    Join Date
    07-14-2017
    Location
    Poland
    MS-Off Ver
    Office 2010
    Posts
    528

    Re: How to code it with array ?

    Try. The results in Sheet2.
    Please Login or Register  to view this content.

+ 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. [SOLVED] Help with VB code to Compare if values in one array exists in another array
    By rv02 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2017, 07:09 AM
  2. [SOLVED] Code into array
    By Burt_100 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-21-2015, 11:37 AM
  3. [SOLVED] code an array into VBA
    By kamelkid2 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-16-2014, 10:15 PM
  4. [SOLVED] Summing Array Variable by Another Value in the Array (VBA Code)
    By lloydgodin in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-18-2013, 10:13 AM
  5. Is it possible to use ARRAY in this code
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-31-2013, 12:49 AM
  6. [SOLVED] What is wrong with this code? (Extract Row from 2D array to 1D array)
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-10-2013, 07:17 AM
  7. [SOLVED] Array Formula vs vBa code - How To Modify My Messy Code To One Of Those
    By ScotyB in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-20-2012, 12:04 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