+ Reply to Thread
Results 1 to 10 of 10

Help to Copy data with conditions from another sheet by Macro VBA

  1. #1
    Forum Contributor
    Join Date
    10-29-2017
    Location
    US
    MS-Off Ver
    2013
    Posts
    142

    Help to Copy data with conditions from another sheet by Macro VBA

    hi all

    I'm beginer with excel want to help

    I have workbook with 04 sheet A, B,C and D. Sheets B and C have data with Column A format as date: 201601, 201602 .... 201701, 201702..... 201801, 201802.

    Now when I type at Cell A1 in sheet A = "2016", I want all row in sheet B and C data have "2016**" copy to sheet D.

    How to do that by macro?

    Thanks./.

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    Welcome to the forum :-) Code below and in the attached sample file.
    Please Login or Register  to view this content.
    Hope that helps. MM
    Attached Files Attached Files
    Last edited by MatrixMan; 10-29-2017 at 12:23 PM.
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  3. #3
    Forum Contributor
    Join Date
    10-29-2017
    Location
    US
    MS-Off Ver
    2013
    Posts
    142

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    Great code, many thanks.

    So I add below code to clear old data before change Cell A1
    Please Login or Register  to view this content.
    There have a small problem that if Sheets B and C format as: ABC-201601-001, DEF-201602-002 ,etc. This mean have characters before and after.

    So could you coding it by VBA, thanks in advanced./.

  4. #4
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    The line of code that looks for the year is this:
    Please Login or Register  to view this content.
    Which means "if the year is at the start of the string" because the return position is 1. If it can be anywhere in the string then change that to this:
    Please Login or Register  to view this content.
    To be safer, if the year is prefixed with a "-" then change it to:
    Please Login or Register  to view this content.
    Hope that helps. MM.

  5. #5
    Forum Contributor
    Join Date
    10-29-2017
    Location
    US
    MS-Off Ver
    2013
    Posts
    142

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    Thanks for your reply, I change code as you help to:
    Please Login or Register  to view this content.
    But it only take data on sheet B to D, not get data from sheet C to D.

    I attacted file with my some data could you help
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    It's copying data from both. I've added a statusbar progress count so you can see (bottom left of the excel window). You could also filter both sheets where the cells contain 2017 and colour them differently, then see the results in sheet D.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    10-29-2017
    Location
    US
    MS-Off Ver
    2013
    Posts
    142

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    Quote Originally Posted by MatrixMan View Post
    It's copying data from both. I've added a statusbar progress count so you can see (bottom left of the excel window). You could also filter both sheets where the cells contain 2017 and colour them differently, then see the results in sheet D.
    Please Login or Register  to view this content.
    Thanks for your replay but This code still only copy from sheet B to D, not to copy from sheet C to D.

    You can see data on sheet C, column B as "9***", You run code then check sheet D again, no data from sheet C was copied

    P/S I saw procesing bar at the bottom.

  8. #8
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    Ah ... copy/paste issue ... This
    Please Login or Register  to view this content.
    should be this:
    Please Login or Register  to view this content.
    The Cells.Clear line was also in the wrong place. Full code below and see attached.
    Please Login or Register  to view this content.
    MM.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    10-29-2017
    Location
    US
    MS-Off Ver
    2013
    Posts
    142

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    Pefect MatrixMan, many thanks with your help.

    Sorry I can only add reputation for you onece, you know I have to add Rep anotherone before can add Rep you again.

    Have a nice day./.

  10. #10
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: Help to Copy data with conditions from another sheet by Macro VBA

    You're very welcome - apologies for my typo and confusion! Appreciate the reps - thank you. :-)

+ 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] Copy (Generate) cells with data from another sheet when conditions met
    By jamewoong in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2017, 08:10 AM
  2. [SOLVED] Copy data and paste it to next sheet with conditions
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-03-2017, 05:26 AM
  3. Copy Data from One sheet to other in same excel with some conditions.
    By Taj48 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-07-2013, 02:03 PM
  4. [SOLVED] Bulk import. (Copy Data from one sheet to a main sheet with conditions)
    By DanzaNZ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-18-2013, 12:24 AM
  5. Help: Copy/link data from one sheet to another based on conditions
    By norvelle in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-06-2012, 10:21 PM
  6. Copy data from one sheet to another sheet with conditions
    By cchoo13 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-22-2009, 11:10 AM
  7. [SOLVED] copy data from one sheet to another under conditions
    By nico in forum Excel General
    Replies: 5
    Last Post: 05-31-2005, 01:05 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