Problem with .Apply in VBA

Taff

Board Regular
Joined
Mar 31, 2004
Messages
151
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I am running the following code to filter info from one sheet to several others, depending on results.
the first section of the code runs well, ie copying to "Back O2.5"
when it moves to the next section, i get 2 issues:
1. a debug on the .Apply - to get around this i need to manually back space the .apply to the previous line then press return to return it to its original place!!
2. When copying the to the worksheet "Home Wins" it keeps copying the orginal top row headers of the original worksheet

Any suggestions on fixes welcome

VBA Code:
Sub Filterselections()

    Dim wsA As Worksheet: Set wsA = Sheets("Match Summaries") ' base data held here
     Dim wsB As Worksheet: Set wsB = Sheets("Back O2.5")
     Dim wsC As Worksheet: Set wsC = Sheets("Home Wins")
  

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

With wsA.[a4:ce215].CurrentRegion


     .AutoFilter 83, "=Back O2.5" 'filter rows with values O2.5 in CE
        .Offset(1).EntireRow.Copy wsB.Range("A" & Rows.Count).End(3)(2) 'copy info to worksheet called Back O2.5
         .AutoFilter
    Rows("4:4").Select
    Selection.AutoFilter
    Range("A5:CE3000").Select
      ActiveWorkbook.Worksheets("Back O2.5").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Back O2.5").Sort.SortFields.Add2 Key:=Range("C5:C79"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Back O2.5").Sort.SortFields.Add2 Key:=Range("D5:D79"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Back O2.5").Sort
        .SetRange Range("A5:CE3000")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 


.AutoFilter 9, ">=" & 0.9 'filter rows with values below -0.9 in colum 9 Supremacy DIff
.AutoFilter 79, ">=" & 0.88
        .Offset(1).EntireRow.Copy wsC.Range("A" & Rows.Count).End(3)(2) 'copy info to worksheet called Home Wins
        .AutoFilter
    Rows("4:4").Select
    Selection.AutoFilter
    Range("A5:CE3000").Select
      ActiveWorkbook.Worksheets("Home Wins").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Home Wins").Sort.SortFields.Add2 Key:=Range("C5:C790"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Home Wins").Sort.SortFields.Add2 Key:=Range("D5:D790"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Home Wins").Sort
        .SetRange Range("A5:CE3000")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply

    End With
Application.CutCopyMode = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End With
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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