shebe228

New Member
Joined
Sep 28, 2017
Messages
46
Complete Macro Newb, so I apologize for my ignorance. I know what the problem is, I am just not sure how to fix it.

I am filtering one spreadsheet (Utilization Report) by a specific Client, Copying all columns and pasting into another workbook (Book 1).
Each Client has its own tab by name in Book 1 and I will repeat the process 47 times until the specific clients are pulled out. The first client works as intended, but my problem is with "Active Window" (its not returning back to the Utilization Report for the filtered data.

I'm just not sure what specific parts of the code to change and how to identify the Utilization Report as the source for filtered data.

Code:
Sub CopyClientUtilInNetworkReports()
'
' CopyClientUtilInNetworkReports Macro
' Copy the CLIENT utilization reports to Book1 - run client in network setup first
'


'
    Rows("1:1").Select
    Selection.AutoFilter
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    Range("B1").Select
    ActiveSheet.Range("$A$1:$S$48588").AutoFilter Field:=2, Criteria1:= _
        "Client 1"
    Columns("A:A").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Windows("Book1").Activate
    Sheets("Client 1").Select
    Range("A1").Select
    ActiveSheet.Paste
    ActiveWindow.ScrollColumn = 6
    ActiveWindow.ScrollColumn = 5
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 2
    ActiveWindow.ScrollColumn = 1
    ActiveSheet.Range("$A$1:$S$48588").AutoFilter Field:=2, Criteria1:= _
        "Client 2"
    Columns("A:A").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Application.CutCopyMode = False
    Selection.Copy
    Windows("Book1").Activate
    Sheets("Client 2").Select
    Columns("A:A").Select
    ActiveSheet.Paste
    ActiveWindow.ScrollColumn = 4
    ActiveWindow.ScrollColumn = 3
    ActiveWindow.ScrollColumn = 1
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Not sure if I understood what you're trying to do correctly, but give this a go.
Code:
Sub CopyClientUtilInNetworkReports()
'
' CopyClientUtilInNetworkReports Macro
' Copy the CLIENT utilization reports to Book1 - run client in network setup first
'
    Dim Dict As Object
    Dim Ky As Variant
    Dim Cl As Range
    Dim UsdRws As Long
    Dim Wbk As Workbook
    Dim Ws As Worksheet
    
    UsdRws = Range("B" & Rows.Count).End(xlUp).Row
    Set Dict = CreateObject("scripting.dictionary")
    Set Wbk = Workbooks("[COLOR=#ff0000]Book1.xls[/COLOR]")
        
    With Dict
        For Each Cl In Range("B2:B" & UsdRws)
            .CompareMode = vbTextCompare
            If Not .exists(Cl.Value) Then .Add Cl.Value, Nothing
        Next Cl
    End With
    
    For Each Ky In Dict.keys
        Rows("1:1").AutoFilter
        With Range("A1:S" & UsdRws)
            .AutoFilter Field:=2, Criteria1:=Ky
            .Copy Wbk.Sheets(Ky).Range("A1")
        End With
    Next Ky
    Range("A1").AutoFilter

End Sub
Change the part in red to reflect the name & extension of the workbook you are copying to.
Also the Utilization Report sheets needs to be the active sheet when you run this.
 
Upvote 0

Forum statistics

Threads
1,215,984
Messages
6,128,110
Members
449,421
Latest member
AussieHobbo

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