Copy row to new sheet based one multiple numbers

Method007

New Member
Joined
Nov 27, 2017
Messages
1
I get a spreadsheet daily that has thousands of lines in it. In the first column are account codes. I am responsible for a few dozen accounts so the majority of the spreadsheet is information I do not need. What I would like to do is run a macro that simply copies all the row related to my accounts from the first sheet over to the blank second sheet. I believe I found code (from Norie on this site - posted below) that could be modified. My concern is that it appears to be looking through the entire spreadsheet (there are numbers everywhere) and I need to limit it to only looking in Column A. Also I went ahead and modified it by putting my account numbers where the Array("bank", "KLM", "firm") part is so it now reflected strArray = Array("000103", "000330", "000665"). When I ran the macro it correctly copied the 2 rows of 000103 and the only row of 000330, but it failed to copy the row for 000665.

If anyone can help guide me, I'd greatly appreciate it.


Sub BankMove()
Dim strArray As Variant
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim NoRows As Long
Dim DestNoRows As Long
Dim I As Long
Dim J As Integer
Dim rngCells As Range
Dim rngFind As Range
Dim Found As Boolean

strArray = Array("bank", "KLM", "firm")

Set wsSource = ActiveSheet

NoRows = wsSource.Range("A65536").End(xlUp).Row
DestNoRows = 1
Set wsDest = ActiveWorkbook.Worksheets.Add

For I = 1 To NoRows

Set rngCells = wsSource.Range("C" & I & ":F" & I)
Found = False
For J = 0 To UBound(strArray)
Found = Found Or Not (rngCells.Find(strArray(J)) Is Nothing)
Next J

If Found Then
rngCells.EntireRow.Copy wsDest.Range("A" & DestNoRows)

DestNoRows = DestNoRows + 1
End If
Next I
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi & welcome to the board.
Does this do what you want?
Code:
Sub FilterCopy()

    Dim Ary As Variant
    Dim UsdRws As Long
    
    UsdRws = Range("A" & Rows.Count).End(xlUp).Row
    Ary = Array("000103", "000330", "000665")
    
    Range("A1").AutoFilter 1, Ary, xlFilterValues
    Range("A1:A" & UsdRws).SpecialCells(xlVisible).EntireRow.copy Sheets("[COLOR=#ff0000]Sheet2[/COLOR]").Range("A1")
    Range("A1").AutoFilter

End Sub
Change the sheet name in red to match the sheet name you want the data copied to.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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