VBA CountIF "Overflow" After Deleting Record

Rex2024

New Member
Joined
Nov 17, 2022
Messages
32
Office Version
  1. 365
Platform
  1. Windows
Using a vba form, I delete a record and then go to "count" the number of events. Once the record is deleted, the countif is returning an "Overflow" error. I know it's because the range no longer equals the number of records, so how do I correct it?

VBA Code:
Sub GetPriorEvents(sEmp)

    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("EventLog")
    Dim myRange As Range
    Set myRange = ws.Columns(2)
    NumPriorEvents = Application.WorksheetFunction.CountIf(myRange, "=" & sEmp)

End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Where exactly are you seeing this error?
Do you have a COUNTIF function on your worksheet somewhere?

Or in the code you posted?
If it is in the code you posted, what are you sending for "sEmp"?

We may need to know about how this VBA code is being called, and how you are deleting the data (are you deleting rows or columns)?
 
Upvote 0
Solution
Hey Joe4,

I was responding and I realized the issue based on your question. I was passing a bad variable sEmp to the Sub. It's been fixed.

Thanks for your help!
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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