+ Reply to Thread
Results 1 to 11 of 11

Macro to Copy and Paste cells if TRUE

  1. #1
    Registered User
    Join Date
    12-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Macro to Copy and Paste cells if TRUE

    Hi,

    I need a macro to copy and paste cells from one worksheet to another, if there is the word true in the column L of that row.

    Can anybody help?

    Thanks in advanced!

  2. #2
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Macro to Copy and Paste cells if TRUE

    I'd go with something like :

    Please Login or Register  to view this content.
    =IF(AND(OR(BLONDE,BRUNETTE,REDHEAD),OR(MY PLACE,HER PLACE),ME),BOW-CHICKA-BOW-WOW,ANOTHER NIGHT ON THE INTERNET)

  3. #3
    Registered User
    Join Date
    12-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to Copy and Paste cells if TRUE

    Hi, thanks for the reply. I'm not that savvy with Macros, what do x and y mean?

  4. #4
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Macro to Copy and Paste cells if TRUE

    My apologies.
    Horrible habit of mine.
    At the start of the code, you see:

    Dim x as integer
    Dim y as integer

    This is declaring them as integers (Whole numbers) telling excel that these are numbers. In this case I'm using x as the reference to the page already containing the data, and y as the reference for the page it's going to.

    Basically this code says:
    Please Login or Register  to view this content.
    x and y are numbers
    Please Login or Register  to view this content.
    y is 1 to start with
    Please Login or Register  to view this content.
    for x = 1 to 10000 means it runs this next chunk of code for every number in between and including 1 and 10000.
    So it starts with x = 1.
    It's saying in the next line if cells(x, 12) x is 1, so cells(1, 12) which is column L, row 1... if that is TRUE then...

    copy row x (1), column A : column L from that worksheet, to this other worksheet, in range row y (y = 1 at the start of this code), column A to L. Once that's done, it increases y by one, meaning the next time it copies over, it'll be on the next line down, since y is then 2, then 3, etc. But only if it's copied something, since it's tucked in as part of the IF-END IF nest.

    Once this completes for the first x (1), it goes to the next x which is 2, so it runs those checks on row 2, and so on and so forth, up to row 10000.

    I just kinda pulled 10000 out of the air, you can set that to whatever you'd like, or we can set something up that figures out its own range.

    mew?
    Last edited by mewingkitty; 12-04-2009 at 03:50 PM.

  5. #5
    Registered User
    Join Date
    12-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to Copy and Paste cells if TRUE

    Hi, I'm still a little bit lost.

    Here's a screenshot:
    The highlighted area is what I'd like to copy, and I'd like it to be copied exactly from Sheet1 to Sheet2. Does this help?

    Thanks

    \1

  6. #6
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Macro to Copy and Paste cells if TRUE

    Pink characters have been changed.

    Please Login or Register  to view this content.
    If you could post your actual workbook, or an example of it, instead of just a picture, I can implement this for you along with a more detailed explanation of what's happening and why.

  7. #7
    Registered User
    Join Date
    12-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to Copy and Paste cells if TRUE

    Ok, I've just removed all the data, I'll upload the file.

    I'd pretty much like those that say TRUE to be copied to Sheet 2, with the first TRUE being first, and the others below that, with no gaps, if that makes sense? Haha.

    Thanks
    Attached Files Attached Files

  8. #8
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Macro to Copy and Paste cells if TRUE

    See attached.
    There's a brief explanation of how to access the code and run it step by step in the worksheet. I think that should clear up any questions you have about further tweaking it?

    Lemme know.

    mew!
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    12-04-2009
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Macro to Copy and Paste cells if TRUE

    Awesome, think I've got the gist now, many thanks!

  10. #10
    Forum Contributor
    Join Date
    12-04-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    127

    Re: Macro to Copy and Paste cells if TRUE

    I smiled when I read the last post!

    After reading all of this, I understood alot more about how code works.

    Could this be method be implemented in my current problem:

    See topic - Search another worksheet

    could your code be modified to search say, Workbook DATABASE ,Column A, row 1 - 5000,
    for any instance / combination of
    Workbook FORM , cell H20? (or whatever cell it is)

    If there is any matches / close matches?

    does the 'close match' bit make it more difficult as its not an exact match?


    Hope you can give some advice.

  11. #11
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Macro to Copy and Paste cells if TRUE

    Cool cool.
    Please mark your thread as solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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