+ Reply to Thread
Results 1 to 5 of 5

[SOLVED] Copy each row from specific columns to another worksheet if criteria is met

  1. #1
    Registered User
    Join Date
    12-23-2015
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    14

    [SOLVED] Copy each row from specific columns to another worksheet if criteria is met

    Sub Services()

    Dim i, x As Long
    Dim airport As String
    Dim ws1 As Worksheet: Set ws1 = ActiveWorkbook.Sheets("Raw Data")
    Dim ws2 As Worksheet: Set ws2 = ActiveWorkbook.Sheets("Services")

    x = 11
    airport = "BM"

    For i = 2 To 500:
    If ws1.Cells(i, 9) = airport Then
    Range(ws2.Cells(x, 1), ws2.Cells(x, 2), ws2.Cells(x, 3), ws2.Cells(x, 4), ws2.Cells(x, 5)).Value = 'This is where it errors' -->Range(ws1.Cells(i, 1), ws1.Cells(i, 2), ws1.Cells(i, 4), ws1.Cells(i, 7), ws1.Cells(i, 8)).Value
    x = x + 1
    End If
    Next i

    End Sub



    The error: It highlights "Range" and comes up with a message saying "wrong number of arguments or invalid property assignment". NEED HELP ASAP PLEASE. Thanks in advance!
    Last edited by JDG94; 12-24-2015 at 08:17 PM.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Copy each row from specific columns to another worksheet if criteria is met

    I think this is a prime example for the use of autofilter. This is untested since you didn't submit a workbook. You may need to amend to make it work on your specific sheet/layout but the code itself is solid.

    Please Login or Register  to view this content.
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Valued Forum Contributor
    Join Date
    10-05-2014
    Location
    Regina, SK Canada
    MS-Off Ver
    Excel for Mac 11
    Posts
    330

    Re: Copy each row from specific columns to another worksheet if criteria is met

    Try this…

    It looks longer but makes it easy to see the corresponding cells that change values (easier to debug and change too).
    There are several ways to make it more efficient too.

    Please Login or Register  to view this content.
    If this has been helpful, please click on the star at the left.

  4. #4
    Registered User
    Join Date
    12-23-2015
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    14

    Re: Copy each row from specific columns to another worksheet if criteria is met

    Yesss this worked perfectly! You legend! Thanks so much!!!!

  5. #5
    Registered User
    Join Date
    12-23-2015
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    14

    Re: Copy each row from specific columns to another worksheet if criteria is met

    Thank you for your reply it worked but because you didnt have the data it was a bit skewed but never mind the next reply solved it. You can ignore the message i sent as well.

+ 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] Fiter multiple criteria and copy columns in specific way
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-04-2015, 03:09 AM
  2. [SOLVED] Copy specific columns to specific columns in another worksheet
    By mahat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2014, 11:24 AM
  3. Copy specific columns from one worksheet to another.
    By Hypatia in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-09-2014, 04:14 PM
  4. How to Copy Specific Columns into a new Specific Worksheet?
    By aevo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-26-2013, 11:07 PM
  5. Copy a specific row and a range of columns to next available row on another worksheet
    By monkey1184 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2013, 05:02 PM
  6. Replies: 3
    Last Post: 06-17-2013, 06:00 AM
  7. [SOLVED] copy select columns instead of entire row if it meets specific criteria
    By liz80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-18-2012, 04:26 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