Row copy tool

fireslguk

Active Member
Joined
Nov 11, 2005
Messages
305
Any recommendations on vba for the following

In Sheet 1

Search for user “Matthew”

Select and copy the row Matthew and paste in sheet 2

Search for user “green”

Select and copy the row green and paste in sheet 2 underneath Matthew row
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try this will search column C

Not sure why you say I think

Do you mean we need to search all 15,000 columns each time?

Code:
Sub My_Find()
Application.ScreenUpdating = False
'Modified  8/7/2018  2:44:27 AM  EDT
Dim SearchString As String
Dim SearchRange As Range
Dim Lastrow As Long
Dim Lastrowa As Long
Dim r As Long
Lastrowa = Sheets(2).Cells(Rows.Count, "C").End(xlUp).Row + 1
With Sheets(1)
    Lastrow = .Cells(Rows.Count, "C").End(xlUp).Row
    SearchString = InputBox("Search for user?")
    Set SearchRange = .Range("C2:C" & Lastrow).Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
    If SearchRange Is Nothing Then MsgBox "The Value" & vbNewLine & SearchString & vbNewLine & "Not Found" & vbNewLine & "I will now exit the script": Exit Sub
    r = SearchRange.Row
    .Rows(r).Copy Sheets(2).Rows(Lastrowa)
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try this will search column C

Not sure why you say I think

Do you mean we need to search all 15,000 columns each time?

Code:
Sub My_Find()
Application.ScreenUpdating = False
'Modified  8/7/2018  2:44:27 AM  EDT
Dim SearchString As String
Dim SearchRange As Range
Dim Lastrow As Long
Dim Lastrowa As Long
Dim r As Long
Lastrowa = Sheets(2).Cells(Rows.Count, "C").End(xlUp).Row + 1
With Sheets(1)
    Lastrow = .Cells(Rows.Count, "C").End(xlUp).Row
    SearchString = InputBox("Search for user?")
    Set SearchRange = .Range("C2:C" & Lastrow).Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
    If SearchRange Is Nothing Then MsgBox "The Value" & vbNewLine & SearchString & vbNewLine & "Not Found" & vbNewLine & "I will now exit the script": Exit Sub
    r = SearchRange.Row
    .Rows(r).Copy Sheets(2).Rows(Lastrowa)
End With
Application.ScreenUpdating = True
End Sub



Lol because the file I want to extract from is at work so I need to check

Also this code at first glance is a once only use per person ?

I need the code to find the same 8 people every time I run it
 
Upvote 0
Ok:
You said:
I need the code to find the same 8 people every time I run it

What 8 named people.
You have not provided those 8 names.
 
Upvote 0
Try this:
Code:
Sub Case_Using()
'Modified  8/7/2018  4:55:12 AM  EDT
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Sheets(1).Activate
Lastrow = Sheets(1).Cells(Rows.Count, "C").End(xlUp).Row
Dim Lastrowa As Long
Lastrowa = Sheets(2).Cells(Rows.Count, "C").End(xlUp).Row
    For i = 1 To Lastrow
        MyVal = Cells(i, 3).Value
            With Cells(i, 1)
                Select Case MyVal
                    Case "Matthew", "Green", "Ali", "Pop", "Go", "One", "Red", "Fox"
                        Lastrowa = Lastrowa + 1
                            Rows(i).Copy Sheets(2).Rows(Lastrowa)
                End Select
            End With
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Hello Fireslguk,

Here's another option. You could move all the names into an array then filter on the array:-


Code:
Sub MoveIt()

Dim ar As Variant
ar = Sheet3.Range("A2", Sheet3.Range("A" & Sheet3.Rows.Count).End(xlUp))

Application.ScreenUpdating = False

For i = 1 To UBound(ar)
    With Sheet1.[A1].CurrentRegion
        .AutoFilter 3, ar(i, 1)
        .Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
        .AutoFilter
    End With
Next i

Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

You'll only have to list all the names into Column A of Sheet3 starting in row2. You can add/delete names to/from the list as required.

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
If you want to use a filter which may be a little faster try this:
Run this script from Sheet(1)

Code:
Sub Filter_Me_With_Array()
'Modified  8/7/2018  8:38:28 AM  EDT
Application.ScreenUpdating = False
Dim Lastrow As Long
Dim Lastrowa As Long
Dim c As Long
Dim Counter As Long
c = 3 ' Column Number Modify this to your need
Lastrow = Cells(Rows.Count, c).End(xlUp).Row
Lastrowa = Sheets(2).Cells(Rows.Count, c).End(xlUp).Row + 1
With Sheets(1).Cells(1, c).Resize(Lastrow)
    .AutoFilter 1, Criteria1:=Array("Matthew", "Green", "Ali", "Pop", "Go", "One", "Red", "Fox"), Operator:=xlFilterValues
    Counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If Counter > 1 Then
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets(2).Cells(Lastrowa, 1)
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,763
Messages
6,180,823
Members
452,997
Latest member
gimamabe71

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top