VBA Code Streamline

Benzoli7

Board Regular
Joined
Jan 11, 2010
Messages
136
Hello,
Can anyone help me streamline this code? I want to avoid "Selecting" and "Activating" as much as possible because this block of code will be repeated several times with different columns. Thanks so much.

HTML:
Sheets("Rate Comparison").Activate
    Range("A6").AutoFilter
    Range("A6").AutoFilter Field:=26, _
        Criteria1:="=New"
    Range("A7").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.SpecialCells(xlCellTypeVisible).copy
    Windows("Rate Comparison Macro1").Activate
    Sheets("Proposed Ranking").Select
    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("C" & FinalRow + 1).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try:
Code:
With Sheets("Rate Comparision")
    .Range("A6").AutoFilter
    .Range("A6").AutoFilter Field:=26, Criteria1:="=New"
    FinalRow = .Range("A7").End(xlDown).Row
    .Range("A7:A" & FinalRow).SpecialCells(xlCellTypeVisible).Copy
End With
Windows("Rate Comparison Macro1").Activate
With Sheets("Proposed Ranking")
    FinalRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
    .Range("C" & FinalRow).PasteSpecial Paste:=xlPasteValues
End With
 
Last edited:
Upvote 0
Thanks so much. That looks much cleaner.

Any advice on speeding up this next bit of code? It is applied to anywhere between 50,000 and 60,000 rows. Screen updating is off and calculation is manual but, it still takes several minutes to process.

HTML:
Sheets("Proposed Ranking").Select
    Range("T1").Value = "COUNTIF"
    Range("T2").Formula = _
            "=COUNTIF('Rate Comparison'!$K$7:K15,B2)"
    LR = Range("A" & Rows.Count).End(xlUp).Row
     Range("T2").AutoFill Destination:=Range("T2:T" & LR), Type:=xlFillDefault
    Calculate


Also, is there any way to make this line look at all rows in column K?

HTML:
"=COUNTIF('Rate Comparison'!$K$7:K15,B2)"


Thanks again.
 
Upvote 0
Try:
Code:
With Sheets("Proposed Ranking")
    .Range("T1") = "COUNTIF"
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("T2").Formula = "=COUNTIF('Rate Comparison'!$K$7:$K$" & LR & ",B2)"
    .Range("T2:T" & LR).FillDown
End With
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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