+ Reply to Thread
Results 1 to 15 of 15

Creating loop check cell value if so copy some cells to a external program

  1. #1
    Registered User
    Join Date
    06-11-2010
    Location
    The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    81

    Creating loop check cell value if so copy some cells to a external program

    I am trying to create a loop with the following details:

    Check value in column J (starting at cell J6), if cell value:
    - equals "Grand Total" then end this macro
    - not equals "Grand Total" then
    Copy J6 run macro A
    Copy K6 run macro B
    Copy R6 run macro C
    - Pop up screen to ask to continue to next
    Then I want it to continue on with the above steps untill a cell in column J equals "Grand Total".

    Hope this is clear enough.

    Example of the code I need to use for copy is:
    Please Login or Register  to view this content.
    Macro code for CopyCellContents is: (Copied it from somewhere on the internet, so this is not my own code but very useful)
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by dutchmaste; 06-02-2017 at 12:30 AM. Reason: Added sample file

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Creating loop check cell value if so copy some cells to a external program

    what/where is grand total?
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    06-11-2010
    Location
    The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Creating loop check cell value if so copy some cells to a external program

    That can be different each time. It is in a pivot table but Grand Total is always somewhere in column J.

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Creating loop check cell value if so copy some cells to a external program

    not quite sure exactly what you want but coded based on what you have explained

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-11-2010
    Location
    The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Creating loop check cell value if so copy some cells to a external program

    I tried the code but it is not recognizing the cell with Grand Total in it (maybe due to the pivot table?

    Hopefully this explains better what I am trying. I want it to first look at cell J6 if not Grand total, then copy cell value J6 to external program, then copy cell K6 to external program, then copy L6 to external program. When done I want it to show pop up and ask to continue (Because I need to add some more in external program). Then I want it to go to J7 and look if not Grand Total, then copy cell value J7 to external program, then copy cell K7 to external program, then copy L7 to external program. When done I want it to show pop up and ask to continue and continue on untill Grand Total is found in a row of column J.

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Creating loop check cell value if so copy some cells to a external program

    best you post an example of what your file looks like

  7. #7
    Registered User
    Join Date
    06-11-2010
    Location
    The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Creating loop check cell value if so copy some cells to a external program

    Added the example file. Also posted in the same file next to it the steps it should take.

  8. #8
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Creating loop check cell value if so copy some cells to a external program

    had a look
    the code is doing exactly what you asked
    the only thing is below was commented in as i didnt know what your macro A,B,C is

    'Copy J6 run macro A
    'Copy K6 run macro B
    'Copy R6 run macro C

    ps i assume you mean L6 and not R6

  9. #9
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Creating loop check cell value if so copy some cells to a external program

    made some changes to the code
    see attached sample file
    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    06-11-2010
    Location
    The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Creating loop check cell value if so copy some cells to a external program

    Please Login or Register  to view this content.
    I tried changing the code into the below, as shown in my sample file at macro. But it is not doing the steps or recognizing th
    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Creating loop check cell value if so copy some cells to a external program

    you are using SetCursorPOS but you havent set up the API for it?

    then for your loops
    what are they meant to do ?
    increment both x and y but you manually set setcursorPOS each time?
    then after the loop is completed then you do LeftClick (which again is not set)
    sendkeys of a cell value

    also see nothing to do with copycellcontents which you posted in your original post

    also i see no reference to external program in the code
    how are you changing to your program before sending keys?

  12. #12
    Registered User
    Join Date
    06-11-2010
    Location
    The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Creating loop check cell value if so copy some cells to a external program

    I def. messed up somewhere. Looks like I made a mistake somewhere either by not saving or overwritting a good script. But you loop seems to work just fine.

    But the SerCursorPOS and LeftClick and Copycellcontents are all mentioned in my example file:
    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: Creating loop check cell value if so copy some cells to a external program

    still dont see no SerCursorPOS
    anyway
    the query on them still stands
    for your loops
    what are they meant to do ?
    increment both x and y but you manually set setcursorPOS each time?
    ie
    Please Login or Register  to view this content.
    x = 1
    setcursorpos 100,670
    y = 1 to 40000
    ...
    x = 2
    setcursorpos 100,670
    y = 1 to 40000
    ...
    etc

    sorry, not close to the API used and how it works properly but it would seem you would want something like this

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-11-2010
    Location
    The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Creating loop check cell value if so copy some cells to a external program

    Humdingaling,
    Thank you very much that you continue on helping eventhough I messed it up somewhere myself. I tried altering it to what you stated above. But the only thing that keeps happening is that I get the pop-up that Grand Total Missing. The sheet normally has some columns hidden. But to make it clear how the sheet is I expanded it all, but still couldn't get it to work.

    I will try to explain what it needs to do:
    Depending on what is mentioned in the row of column J:J I need to copy certain information to different places in a external non-windows program. So most logical step I think would be:
    1. Check if row 6 in column J equals Grand Total
    1.a. If so, then end macro
    1.b. If not, then:
    1.b.1. copy value in same row from column K to point X on external program
    1.b.2. copy result mentioned in same row from column T to point Y on external program (Cell contains a formula)
    1.b.3. copy result mentioned in same row from column V to point Z on external program (Cell contains a formula)
    2. When done with the above, provide pop-up to confirm to continue. (Because we need to do some more manual handling in the external program before next value can be entered)
    2.a When exit selected, end macro
    2.b When continue selected:
    2.b.1. Check if row 7 in column J equals Grand Total
    2.b.1.a. If so, then end macro
    2.b.1.b. if not, then:
    2.b.1.b.1. mouse click point W on external program
    2.b.1.b.2. copy value in same row from column K to point X on external program
    2.b.1.b.3. copy result mentioned in same row from column T to point Y on external program (Cell contains a formula)
    2.b.1.b.4. copy result mentioned in same row from column V to point Z on external program (Cell contains a formula)
    3. When done with the above, provide pop-up to confirm to continue. (Because we need to do some more manual handling in the external program before next value can be entered)
    3.a When exit selected, end macro
    3.b When continue selected, start at 2.b.1. but do next row (8, then 9, then 10, etc.)

    I know some of the cells selected are different then provided before but that was because those cells contains more information then needs to be filled in. So I created a extraction some cells further down.

    I have uploaded a new and hopefully better example file.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    06-11-2010
    Location
    The Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    81

    Re: Creating loop check cell value if so copy some cells to a external program

    humdingaling,

    I fixed my script. When entering your loop script into my script. It works but as soon as I change the sendkey to be equals to the line it is processing it goes wrong:
    Example: (Both are mentioned in coding below as well to show in complete picture)
    Script works with
    Please Login or Register  to view this content.
    As soon as change it to
    Please Login or Register  to view this content.
    Here is the complete coding I have now. Which doesn't seem to work, because it does go to the first cell (Does not enter anything) but then directly shows pop-up with "Grand Total Missing"

    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. Copy from external program, paste values into excel into a protected spreadsheet
    By bonniefide in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-23-2017, 03:55 AM
  2. VBA program for cell increment from external file
    By dineshkdk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-17-2016, 04:19 AM
  3. VBA Loop that check cells in a column(Range)then copy if criteria match
    By Eben in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2015, 02:43 AM
  4. [SOLVED] External program does not recognize some excel cells
    By ddadakas in forum Excel General
    Replies: 5
    Last Post: 04-25-2014, 04:15 PM
  5. [SOLVED] Loop through column check for colored cell and copy that cell to cells below it.
    By RENCE19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2013, 04:51 AM
  6. [SOLVED] execute external program when cell reaches certain value
    By Brendan DJ Murphy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-08-2011, 10:27 AM
  7. Loop Program to Copy/Paste from One Sheet to Another
    By smlaff01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-13-2007, 11:33 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