+ Reply to Thread
Results 1 to 10 of 10

Help to copy data to another sheet with conditions

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

    Help to copy data to another sheet with conditions

    Hi all,

    I have sheet("data_new") and want to copy data to another sheet with conditions that:

    Please Login or Register  to view this content.
    Please help me to do that with VBA code, i try hard but there's mistake with my code
    Attached Files Attached Files
    Last edited by sbv1986; 03-28-2019 at 08:22 PM.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Help to copy data to another sheet with conditions

    See how this works for you.

    Please Login or Register  to view this content.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

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

    Re: Help to copy data to another sheet with conditions

    Thanks @JLGWhiz but code yellow in line If .Cells(i, "M").Value + .Cells(i, "N").Value < .Cells(i, j).Value Then

    with info: Run time error 13, type mismatch

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Help to copy data to another sheet with conditions

    You need to edit your Data_new worksheet to eliminate
    #DIV/0!
    these type error displays and any other non-numeric cell values in columns M and N. They are the cause of your error message. You cannot subtract a numeric value from a non-numeric value and vba will definitely let you know it is there. You could put an 'On Error Resume Next' Statement in the code which would just step over those rows, but it is better that you clean the database so the code runs properly.

    The code was working fine until it hit row 100.

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

    Re: Help to copy data to another sheet with conditions

    Pefect @JLGWhiz, I delete cell #DIV/0! anf code worked okey.

    May i have final question, with each value has just found in column B of sheets (higher/lower"), I want to compare with old data in sheets("Data_Old").

    How can I add value from sheets("data_old") to column(D) for each value into sheets("higher") or sheets("lower").

    Many thanks./.

  6. #6
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,317

    Re: Help to copy data to another sheet with conditions

    Administrative Note:

    We would love to help you with your query; however, you need to include code tags around your code.

    Please take a moment to add the tags. 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, and it also maintains VBA formatting.

    Click on Edit to open your thread, then 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

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    HTH
    Regards, Jeff

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

    Re: Help to copy data to another sheet with conditions

    thanks @jeffreybrown, I've just edit as you said.

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Help to copy data to another sheet with conditions

    Make sure columns M and N are all numeric in data_old and then try this.

    Please Login or Register  to view this content.

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

    Re: Help to copy data to another sheet with conditions

    Thanks for your respond @JLGWhiz but this code don'w work that I want
    With code working well on #2, I want code adding data in sheets("data_old") into sheets("higher or lower").column(D) when each cell in sheets(higher or lower).column("B") match with each cell in sheets("data_old').row(2).

    Sorry I mark this thread as solved and create new onw at this: https://www.excelforum.com/excel-pro...ew-thread.html

  10. #10
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Help to copy data to another sheet with conditions

    That needs to be started as a new thread. It is a different requirement than the original post, per forum rules as you obviouly have 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. Help to Copy data with conditions from another sheet by Macro VBA
    By sbv1986 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-30-2017, 06:46 AM
  2. [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
  3. [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
  4. 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
  5. [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
  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