+ Reply to Thread
Results 1 to 12 of 12

VBA to transfer data that satisfies a condition from one sheet to another in same workbook

  1. #1
    Registered User
    Join Date
    10-07-2013
    Location
    Bozeman, Montana
    MS-Off Ver
    Excel 2013
    Posts
    6

    VBA to transfer data that satisfies a condition from one sheet to another in same workbook

    Hi there! I'm very new to VBA and am trying to write a code that will do the following....

    On the first sheet I have a column that lists customer IDs, a second column that lists the amount each customer has purchased, and a third column that lists the amount each customer has paid so far.

    On the second sheet I need to report the customer IDs and amounts for any customer that still owes more than $1,000. I need this to work even if the data changes...especially if there are more/less customers.

    This is how far I got before getting very confused....I know I need to do a loop, but just keep getting more confused. Help!!

    Please Login or Register  to view this content.
    Last edited by alansidman; 10-07-2013 at 08:40 PM. Reason: code tags added

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,877

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (I have added the code tags for you this time. Please adhere to all our rules in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    Does the customer IDs repeat? or any new purchases/payments will be added to the existing row (meaning customer IDs only appear once)?

    If the IDs only appear once, you can simply type a formula of example: =B2-C2 in cell D2

  4. #4
    Registered User
    Join Date
    10-07-2013
    Location
    Bozeman, Montana
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    Thanks, but I need to allow for new customer IDs and purchases/payments to be added and populate dynamically. I wish I could just use a formula!!

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    By populating 'dynamically', do you mean you run the macro manually after the new customer IDs are added, or do you mean the macro should run automatically after new customer IDs are entered or existing data is refreshed/entered?

    How are the existing/new data entered?

  6. #6
    Registered User
    Join Date
    10-07-2013
    Location
    Bozeman, Montana
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    No, sorry. The new data is entered manually on sheet 1. Then I'll have a macro button on sheet 2 that will "pull" any customer ID and corresponding amount owing from sheet 1 to the correct columns in sheet 2....but only if the customer owes more than $1,000. By dynamic, I mean that if I add more customers or take away customers it should "read" those lines the same. Does that make sense?

  7. #7
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    Try running this macro with your button on sheet2:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-07-2013
    Location
    Bozeman, Montana
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    Thank you for your response. It's not working, but you've given me a place to work from at least. I think I should be able to work through it from here. Thanks again!

  9. #9
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    Quote Originally Posted by KLL2014 View Post
    It's not working
    Well, it's working when I tested on dummy data. If there are more problems, post a sample of your workbook.

  10. #10
    Registered User
    Join Date
    10-07-2013
    Location
    Bozeman, Montana
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    Here you go!
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    10-07-2013
    Location
    Bozeman, Montana
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    I'm getting Runtime Error '9':
    Subscript out of range

  12. #12
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA to transfer data that satisfies a condition from one sheet to another in same work

    Try this:
    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] Macro to copy data rows to a summary worksheet if the row satisfies a condition
    By cjfreeseman in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-05-2012, 03:33 AM
  2. Transfer Data from 1 sheet to another with a condition
    By raunakkolte in forum Excel General
    Replies: 2
    Last Post: 02-21-2011, 07:30 AM
  3. A condition true if one element in a row of a matrix satisfies it
    By giovannioh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-29-2010, 07:09 AM
  4. Transfer Data To Different Sheet Based on Condition
    By Strugggler in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-27-2008, 08:42 PM
  5. [SOLVED] How to input cellcontent within worksheets if satisfies condition
    By Vinitha in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-03-2006, 08:00 AM

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