+ Reply to Thread
Results 1 to 10 of 10

Copying rows based on criteria

Hybrid View

  1. #1
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Copying rows based on criteria

    Is this what your wanting?

    Option Explicit
    Private Sub CommandButton1_Click()
     Dim shName As String, cFind As Range
     Dim sh As Worksheet, lr As Long, c As Range
     
     Set sh = Sheets("MasterSheet")
     lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
     For Each c In sh.Range("a2:a" & lr)
        Select Case c.Value
            Case Is = "AAAA"
                shName = "Centre1"
            Case Is = "BBBB"
                shName = "Centre2"
            Case Is = "XXXX"
                shName = "Centre3"
            Case Is = "YYYY"
                shName = "Centre4"
            Case Is = "ZZZZ"
                shName = "Centre5"
        End Select
        With Worksheets(shName).Columns(1)
            Set cFind = .Find(c.Offset(, 1).Value, LookIn:=xlValues, LookAt:=xlWhole)
            If cFind Is Nothing Then
                .Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, 3).Value = _
                    c.Offset(, 1).Resize(, 3).Value
            End If
        End With
     Next
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  2. #2
    Registered User
    Join Date
    08-04-2012
    Location
    cardiff
    MS-Off Ver
    Excel 2007
    Posts
    49

    Re: Copying rows based on criteria

    Mike7952 - thankyou - you are amazing

+ 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] Macro for copying rows in sheet1 to end of existing rows in sheet2 based on criteria
    By Karl Gustaf Karsten in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2015, 04:19 AM
  2. Copying rows into new workbook, based on set criteria
    By newbie200390 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2015, 05:39 PM
  3. [SOLVED] Copying Rows of Data Based on Criteria
    By harrydnyc in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-06-2011, 03:34 AM
  4. Copying rows from another sheet based on specific criteria
    By jamesbrown008 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-06-2011, 01:53 PM
  5. Replies: 0
    Last Post: 07-21-2010, 07:12 PM
  6. Copying rows in range based on criteria
    By rhudgins in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-20-2010, 12:48 PM
  7. Copying whole rows based upon one criteria
    By kirbster1973 in forum Excel General
    Replies: 2
    Last Post: 05-26-2005, 05:15 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