+ Reply to Thread
Results 1 to 11 of 11

simple if statement

  1. #1
    Registered User
    Join Date
    12-02-2014
    Location
    toronto
    MS-Off Ver
    2013
    Posts
    11

    simple if statement

    Hi all,

    I need some help. I need a quick VBA scripted IF statement (macro) that compares 2 cells within the same row (in this SAMPLE cells A and B) in sheet 1.

    If the cells are equal then the ENTIRE row needs to be copied and pasted onto sheet 2.
    If they are not equal then the ENTIRE row needs to be copied TWICE onto sheet 2 and this needs to loop until it has gone through all lines.

    Sample attached. thanks in advance!
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: simple if statement

    Hi ivector

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

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    12-02-2014
    Location
    toronto
    MS-Off Ver
    2013
    Posts
    11

    Re: simple if statement

    John,

    this code works for the sample I provided beautifuly. if I wanted to apply it to another sheet with columns other than "A" or "B", what variables would I have to change in the code to make it work?

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: simple if statement

    Hi ivector

    That depends...are the Columns that are being compared adjacent?

  5. #5
    Registered User
    Join Date
    12-02-2014
    Location
    toronto
    MS-Off Ver
    2013
    Posts
    11

    Re: simple if statement

    yes they are

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: simple if statement

    Hi ivector

    What are the comparable Columns; in your Sample Data they were "A" and "B".

  7. #7
    Registered User
    Join Date
    12-02-2014
    Location
    toronto
    MS-Off Ver
    2013
    Posts
    11

    Re: simple if statement

    the columns would be named "Qty" and "Qty adjusted" respectively or would generally fall under columns "R" and "S"

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: simple if statement

    Hi ivector

    You say
    would generally fall under columns "R" and "S"
    Does that infer they could be "Somewhere else"?

    If yes, then the Code will need to find them. This can be done but you'll need to provide a new Workbook that has the SAME Structure as your Actual File...proprietary information sanitized.

    One further point of caution, if either of the Worksheets has Headers the Code will not perform as expected.

    So, it'll behoove you to attach a File that truly represents the Structure of what you have.

    On the other hand, if neither Worksheet has Headers AND Columns will ALWAYS be "R" and "S" you need change only one Line of Code (I think).

    Change this Line from
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    Last edited by jaslake; 12-05-2014 at 05:22 PM.

  9. #9
    Registered User
    Join Date
    12-02-2014
    Location
    toronto
    MS-Off Ver
    2013
    Posts
    11

    Re: simple if statement

    Thank you very much for your help Jaslake! works like a charm. Cheers!

    -Vector

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: simple if statement

    You're welcome...glad I could help.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  11. #11
    Registered User
    Join Date
    12-02-2014
    Location
    toronto
    MS-Off Ver
    2013
    Posts
    11

    Re: simple if statement

    done......

+ 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] Simple VBA If Statement help
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-07-2013, 09:37 AM
  2. [SOLVED] Help with simple IF statement
    By timohteee in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-22-2013, 10:57 PM
  3. simple:IF statement
    By Rick-O-Shay in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 12-31-2009, 01:44 AM
  4. simple If-then statement
    By eonizuka in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-22-2009, 07:37 PM
  5. simple for you if statement fix
    By britt.govols in forum Excel General
    Replies: 1
    Last Post: 09-07-2006, 02:52 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