Results 1 to 14 of 14

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

Threaded View

  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?

    Private Sub CommandButton1_Click()
        a = Worksheets("Mar'19").Cells(Rows.Count, 1).End(xlUp).Row
    
        For i = 2 To a
            If Worksheets("Mar'19").Cells(i, 2).Value = "3'5" Then
                Worksheets("Mar'19").Rows(i).Copy
                Worksheets("3.5").Activate
                b = Worksheets("3.5").Cells(Rows.Count, b).End(xlUp).Row
                Worksheets("Sheet2").Cells(b + 1, 1).Select
                ActiveSheet.Paste
                Worksheets("Sheet1").Activate
            End If
        Next
    
        Application.CutCopyMode = False
        ThisWorkbook.Worksheets("Mar'19").Cells(1, 1).Select
    End Sub
    Last edited by jeffreybrown; 09-28-2019 at 10:34 AM. Reason: Please use code tags!

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