VBA Copy and Paste Isn't Working with Additional Sort Filters

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
I was able to get help on this forum not to long ago on a solution that worked beautifully. However, I have tried to augment the number of routines.

Essentially, what I am trying to do is run a series of sort & copy/paste to another sheet.

The sorts are all well defined, but the copy/paste only works on the one sort and not all.

This is a working sort code:
Code:
Sub Sort_IP()
'
' Sort_IP Macro
'

'
Sheets("IP Breakout").Select
    Columns("E:E").Select
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("IP Breakout").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("IP Breakout").Sort.SortFields.Add Key:=Range("E1") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("IP Breakout").Sort
        .SetRange Range("A2:M984225")
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

This is the working copy/paste code that I obtained from this forum:
Code:
Sub EncID_IP()
'.:: Extract EncID
'
    Dim lRow As Long ' East to West
    Dim bCount As Byte '1,2,3
    Dim sServiceHit As String 'Service used to find EncID
    Dim rRange As Range, rCell As Range 'What am I cycling through?
    Dim ws As Worksheet 'Canvas

    Sheets("IP Breakout").Select
    Set ws = Sheets("Results IP") 'dumping ground
    ws.Range("A1") = "EncID" 'extract data
    Set rRange = Range("A2", Range("A" & Rows.Count).End(xlUp)) 'Create a dynamic range to search

    lRow = 2 ' go to 2 deep
    For Each rCell In rRange 'look at every cell in the dynamic range
        If sServiceHit <> rCell.Offset(, 4) Then
           sServiceHit = rCell.Offset(, 4)
           bCount = 0
        End If
        If bCount < 2 Then ' if  X < 2
            ws.Cells(lRow, "A") = rCell 'Canvas cell A + X
            bCount = bCount + 1 'Add to my count by 1
            lRow = lRow + 1 ' Add to my row by 1
        End If
    Next rCell

End Sub

What I have been doing is running a sort like the below directly followed by "Sub EncID_IP" without any success with the copy/paste method:

Here is one of the sorts:
Code:
Sub Sort_Var1High_IP()
'
' Sort_Var1High_IP Macro
'

'
    Sheets("IP Breakout").Select
    Range("C1").Select
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("IP Breakout").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("IP Breakout").Sort.SortFields.Add Key:=Range( _
        "E2:E500000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.Worksheets("IP Breakout").Sort.SortFields.Add Key:=Range( _
        "N2:N500000"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.Worksheets("IP Breakout").Sort
        .SetRange Range("A1:P500000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

Below is how I envisioned using these all stringed together:
Code:
Sub Generate()
Dim Start_Time, end_time
Start_Time = Now() ' start the clock
Application.ScreenUpdating = False

Application.StatusBar = "Processing 1 of 13: IP Breakout..."
Call UnhideAll

Application.StatusBar = "Processing 2 of 13: IP Breakout..."
Call IP_Pick

Application.StatusBar = "Processing 3 of 13: IP High-Count Services Hit..."
Call Sort_IP
Call EncID_IP

Application.StatusBar = "Processing 4 of 13: IP Base v. Expected Comparsion..."
Call Sort_Var1High_IP
Call EncID_IP
Call Sort_Var1Low_IP
Call EncID_IP

Application.StatusBar = "Processing 5 of 13: IP Base v. Cash Comparison..."
Call Sort_Var2High_IP
Call EncID_IP
Call Sort_Var2Low_IP
Call EncID_IP

Application.StatusBar = "Processing 6 of 13: IP Expected v. Cash Comparison..."
Call Sort_Var3High_IP
Call EncID_IP
Call Sort_Var3Low_IP
Call EncID_IP

Application.StatusBar = "Processing 7 of 13: OP Breakout..."
Call OP_Pick

Application.StatusBar = "Processing 8 of 13: OP High-Count Services Hit..."
Call Sort_OP
Call EncID_OP

Application.StatusBar = "Processing 9 of 13: OP Base v. Expected Comparsion..."
Call Sort_Var1High_OP
Call EncID_OP
Call Sort_Var1Low_OP
Call EncID_OP

Application.StatusBar = "Processing 10 of 13: OP Base v. Cash Comparison..."
Call Sort_Var2High_OP
Call EncID_OP
Call Sort_Var2Low_OP
Call EncID_OP

Application.StatusBar = "Processing 11 of 13: OP Expected v. Cash Comparison..."
Call Sort_Var3High_OP
Call EncID_OP
Call Sort_Var3Low_OP
Call EncID_OP

Application.StatusBar = "Processing 12 of 13: Removing Duplicates..."
Call Unique_OP
Call Unique_IP

Application.StatusBar = "Processing 13 of 13: Buildinng ADS Criteria..."
Call HideAll

Application.StatusBar = ""

Sheets("ADS Criteria").Select 'Land me at the end
Range("J2").Select

Application.ScreenUpdating = True
end_time = Now() 'stop
MsgBox "EAS Generator processed entire population in " & DateDiff("S", Start_Time, end_time) & " seconds."

End Sub

Any help would be appreciated.
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Watch MrExcel Video

Forum statistics

Threads
1,126,945
Messages
5,621,760
Members
415,854
Latest member
Tutu123

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
Top