VBA code for COUNTIF formula to determine different end of range

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
929
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am looking to speed up a macro of mine, specifically a COUNTIF formula and I was wondering if the following is possible:

My COUNTIF formula is basic: =COUNTIF(A:A,A2)

When I utilize it I am doing so by entering the VBA code:

Code:
 LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
Range("T2:T" & LastRowColumnA).Formula = "=COUNTIF(C[-19],RC[-19])"

to determine what the last cell is in which to copy down the formula, however the count if formula is still referencing all of column A.

Is there a way to modify this formula in VBA to determine where the data in A ends so I do not have to reference it all? Would this speed up the calculation?

Any ideas would be greatly appreciated, thank you

Carla
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Countif only uses the used range, so as long as the usedrange is reporting correctly there shouldn't be any change in performance.
If you do Ctrl End does that take you to the last row with data?
 
Upvote 0
I found that it wasn't the formula being slow but having the formula in place while using filters afterward. I fixed this by using the COUNTIF formula to get the data, copy and pasting the results as special values (therefor removing the formula) and then manipulating the data (filters etc).

Thank you for your help. I have another question but since it is unrelated to the title of this post I will start a new thread.

Thank you again

Carla
 
Upvote 0
Glad you figured it out & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,271
Members
452,628
Latest member
dd2

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