Looping Through auto-filtering values

Aldaron47

New Member
Joined
Nov 6, 2017
Messages
7
Hello all,

I have two spreadsheets, one containing user IDs ("Report1") and one containing every information we have about the user with that ID "MASTER_Detail_18.07.2018".

I have created a VBA macro that takes a specific ID ( hardcoded) and uses it as a filter in the "MASTER_Detail_18.07.2018" spreadsheet and then copies two values of the identified user row to the "Report1" spreadsheet which contains the userID.

What I am trying to accomplish is to make the userID used in the filtering to be automatically updated from values on a column. Most specifically I want to loop through column A of "Report1" spreadsheet and for each value of the column to filter the "MASTER_Detail_18.07.2018" spreadsheet, run the code for the copy and then move to the next value of column A of "Report1" spreadsheet.

Following is the code I have managed to create so far

Code:
Sub BannerUserMacro()


Windows("Banner Users 08-08-2018.xlsx").Activate
    Sheets("MASTER_Detail_18.07.2018").Select
    ActiveSheet.ListObjects("HRStaff").Range.AutoFilter Field:=6, Criteria1:="MSRA275"
    Range("D3", Range("D1048576").End(xlUp)).Select
    Selection.Copy
    
    Sheets("Report1").Select
    For i = 1 To 2000
        If Cells(i, 1).Value = "MSRA275" And Not IsEmpty(Cells(i, 1).Value) Then
            Cells(i, 4).PasteSpecial Paste:=xlPasteValues
        End If
    Next i
        
    Sheets("MASTER_Detail_18.07.2018").Select
    Range("O3", Range("O1048576").End(xlUp)).Select
    Selection.Copy


    Sheets("Report1").Select
    For i = 1 To 2000
        If Cells(i, 1).Value = "MSRA275" And Not IsEmpty(Cells(i, 1).Value) Then
        Cells(i, 5).PasteSpecial Paste:=xlPasteValues
        End If
    Next i


End Sub

Any help will be greatly appreciated
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about
Code:
Sub getID()
   Dim Cl As Range
   Dim Mws As Worksheet, Rws As Worksheet
   
   Set Mws = Workbooks("Banner Users 08-08-2018.xlsx").Sheets("MASTER_Detail_18.07.2018")
   Set Rws = Workbooks("Banner Users 08-08-2018.xlsx").Sheets("Report1")
   
   With CreateObject("scripting.dictionary")
      For Each Cl In Mws.Range("F3", Mws.Range("F" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Array(Cl.Offset(, -2).Value, Cl.Offset(, 9).Value)
      Next Cl
      For Each Cl In Rws.Range("A1", Rws.Range("A" & Rows.Count).End(xlUp))
         Cl.Offset(, 3).Resize(, 2).Value = .Item(Cl.Value)
      Next Cl
   End With
End Sub
This assumes that the IDs are in col F of the Master sheet
 
Upvote 0
Thank you very much for posting your answer. I changed just some values because the IDs were located in column G and the offsets to match the columns from where I copied the data and it worked like a charm.;)
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
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