VBA Copy over to Sheet2

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,168
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have around 50,000 rows of data. What I need to do is if column O contains "Access Acct" then copy over all of the ID numbers that are associated with it. That would be the rows in yellow. Thanks in advance!

Edison2.csv
ABCDEFGHIJKLMNO
1IDNameOtherRepationshipFnameLnameStreetCityState ZipPhone TypePhoneEmail AddressAcces
21111AAAAAccess Acct
31111AAAAMother
41111AAAAMother
51111AAAAMother
61111AAAAFather
71111AAAAFather
81111AAAA
91111AAAA
101111AAAAMother
111111AAAACousin
121111AAAACousin
131111AAAASister
142222BBBB
152222BBBBMother
162222BBBBMother
172222BBBBAunt
183333CCCCMother
193333CCCCFather
203333CCCCGrandmother
213333CCCCMother
223333CCCCMother
233333CCCCGrandfather
243333CCCCGrandmother
254444DDDDMother
264444DDDDFather
274444DDDDMother
285555EEEEMother
295555EEEEMother
305555EEEEMother
315555EEEEFather
327777FFFFGrandfatherAccess Acct
337777FFFFGrandfather
Sheet3
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try this. Haven't tested it with mega rows. Would probably need an array for 1000's of rows.

VBA Code:
Sub Do_It()
    Dim ws As Worksheet, sh As Worksheet
    Dim rng As Range, c As Range
    Dim LstRw As Long, fRng As Range

    Set ws = ActiveSheet
    Set sh = Sheets("Sheet2")
    With ws
        Set rng = .Range("O2:O" & .Cells(.Rows.Count, "O").End(xlUp).Row)
        For Each c In rng.Cells
            If c = "Access Acct" Then
                .Range("A1").AutoFilter field:=1, Criteria1:=c.Offset(, -14)
                LstRw = .Cells(Rows.Count, "A").End(xlUp).Row
                Set fRng = .Range("A2:N" & LstRw).SpecialCells(xlCellTypeVisible)
                fRng.Copy sh.Cells(sh.Rows.Count, "A").End(xlUp).Offset(1)
            End If

            If .AutoFilterMode = True Then .AutoFilterMode = False
        Next c
    End With


End Sub
 
Upvote 0
That is the problem, It will only say Access Acct once (usually the first line). If it does then I need all of the data associated with that ID #. For instance, it says Access Acct with 1111 then I need all of the 1111 data copies to Sheet2.
 
Upvote 0
Okay thanks! I tried it and it works. I appreciate it.
 
Upvote 0

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

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