+ Reply to Thread
Results 1 to 14 of 14

Copy and paste to another workbook if specific criteria is met VBA

  1. #1
    Registered User
    Join Date
    09-27-2019
    Location
    Lagos, Nigeria
    MS-Off Ver
    Office 365 Excel
    Posts
    20

    Copy and paste to another workbook if specific criteria is met VBA

    I am trying to create VBA code which copies rows from one workbook (Test Report.xlsx) and then pastes that copied row into another workbook(Test Final Report.xlsx), if it meets specific criteria when the commandbutton is clicked. The criteria to copy and paste is a if a cell in the second column in the table contains the critera 3'5, copy that row and then paste it into another workbook. I've tried the following but when I go to run, it just selects cells specified in the line of code before End Sub. I need assistance with this, please see below the code which keeps failing me. What am I doing wrong and what should I do to make it right?

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 09-28-2019 at 10:34 AM. Reason: Please use code tags!

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copy and paste to another workbook if specific criteria is met VBA

    You mention two worksheets, ("3.5" and "Sheet2"). This is a little confusing. What is the name of the worksheet in Test Final Report.xlsx where you want to paste the copied rows? Where in that destination worksheet do you want to paste those rows?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    09-27-2019
    Location
    Lagos, Nigeria
    MS-Off Ver
    Office 365 Excel
    Posts
    20

    Re: Copy and paste to another workbook if specific criteria is met VBA

    Apologies, see the code here which is giving me problems:

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 09-28-2019 at 10:34 AM. Reason: Please use code tags!

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copy and paste to another workbook if specific criteria is met VBA

    Place this macro in the Test Report.xlsx workbook and save the workbook as a macro-enabled file. The macro assumes you have headers in the first row of sheets("Mar'19") and that there are no blank rows in your data. It also assumes that both workbooks are open.
    Please Login or Register  to view this content.

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

    Re: Copy and paste to another workbook if specific criteria is met VBA

    Hi numberonelevelit and Welcome to the forum,

    Administrative Note:

    Please use code tags when posting 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, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags.

    Click on Edit to open your post, 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
    HTH
    Regards, Jeff

  6. #6
    Registered User
    Join Date
    09-27-2019
    Location
    Lagos, Nigeria
    MS-Off Ver
    Office 365 Excel
    Posts
    20

    Re: Copy and paste to another workbook if specific criteria is met VBA

    Tried this, brings an error message saying runtime error 1004 application defined or object defined error.

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copy and paste to another workbook if specific criteria is met VBA

    Which line of code is highlighted when you click "Debug"? Can you attach copies of your two files (de-sensitized if necessary)? It would make it easier to test possible solutions.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copy and paste to another workbook if specific criteria is met VBA

    The headers is the sheet "Mar'19" in row 7 are totally different from the headers in row 10 of the sheet "3.5". They also have a different number of columns. When copying the rows from "Mar'19" to "3.5" I don't know into which columns to paste the data. For example, sheet "3.5" has these four headers: UBA, EURO, CHEQUE BOOK NO. and PETTY CASH but there are no corresponding headers in "Mar'19". Please clarify in detail referring to specific columns, what data you want to copy from "Mar'19" and exactly into which columns in "3.5" you want to paste that data.

  9. #9
    Registered User
    Join Date
    09-27-2019
    Location
    Lagos, Nigeria
    MS-Off Ver
    Office 365 Excel
    Posts
    20

    Re: Copy and paste to another workbook if specific criteria is met VBA

    Any row containing 3'5 in Mar'19 needs to pasted into 3.5. I've sent you an updated version of Test Final Reportc. From "Mar'19 columns date, details of payment and amount are the only rows that need copying, then "from "3.5" pasting into the columns date, payment reason, total.

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copy and paste to another workbook if specific criteria is met VBA

    Try:
    Please Login or Register  to view this content.
    Make sure that there are always 2 blank rows above the "TOTAL" row in "3.5" sheet.

  11. #11
    Registered User
    Join Date
    09-27-2019
    Location
    Lagos, Nigeria
    MS-Off Ver
    Office 365 Excel
    Posts
    20

    Re: Copy and paste to another workbook if specific criteria is met VBA

    It works. Thank you.

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copy and paste to another workbook if specific criteria is met VBA

    You are very welcome.

  13. #13
    Forum Contributor
    Join Date
    12-18-2019
    Location
    chennai
    MS-Off Ver
    excel 2010
    Posts
    141

    Re: Copy and paste to another workbook if specific criteria is met VBA

    Hi Some one please help me. I want similar macro for the below. Kindly helpAttachment 674396

    I have the below data.

    Column B and C is fixed numbers. Coulmn D to H is Qty information Column J to N is Amount.

    I need to filter non blank cell of Column B and then i need to paste this in next worksheet. While pasting i need to consider Column D Qty and Column J Amount along with fixed columns of B&C

    Like this i need to do for all Qty Columns. I have very large data every time while doing manually its taking more time.

    Some one please help me VBA code for this please.

  14. #14
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,810

    Re: Copy and paste to another workbook if specific criteria is met VBA

    According to Forum rules, you should not post your question in another member's thread. Please start your own new thread and inlcude a link to this thread if you think it is useful. If you send me a private message with a link to your thread, I will be happy tp have a look at it.
    Your link doesn't work. Please see the yellow banner at the top of this page for instructions on how to attach a file.
    Last edited by Mumps1; 04-25-2020 at 09:15 AM.

+ 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 and Specific Paste based on Criteria
    By rakotonirinas in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 05-16-2019, 11:42 AM
  2. [SOLVED] Find specific text within workbook's name, copy and paste it to specific cell
    By axtryo in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-09-2017, 02:57 AM
  3. Copy Paste based on Specific Criteria
    By kittu55 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-06-2015, 08:58 AM
  4. Copy paste last row from each workbook in master workbook on header criteria
    By farrukh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-30-2013, 07:28 AM
  5. [SOLVED] Copy Specific Cells Across all worksheets in a Workbook and Paste Into single New Workbook
    By thunt13 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-14-2013, 10:43 AM
  6. [SOLVED] Copy specific data from one workbook to another workbook with certain criteria
    By marc5354 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-12-2012, 12:09 PM
  7. Copy specific data from one workbook to another workbook if certain criteria
    By ejschulte2001 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-12-2010, 05:58 PM

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