VBA countif in target.row

PATSYS

Well-known Member
Joined
Mar 12, 2006
Messages
1,749
Hi all,

Thsi seems so simple and yet I have spent several minutes already...

I have a worksheet_change event that I want to fire if the count of the value "check" in the target row (from column B:J) is greater than 0.

I have the below incomplete code,

Rich (BB code):
Private Sub worksheet_change(ByVal target As Range)

Dim TRowNum As Integer

TRowNum = target.Row

If WorksheetFunction.Countif(Range("B" & trownum & ":" "J" & trownum )) then

End Sub

The bolded line is where I get the error.

Can somebody tell me why?

Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,442
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi all,

Thsi seems so simple and yet I have spent several minutes already...

I have a worksheet_change event that I want to fire if the count of the value "check" in the target row (from column B:J) is greater than 0.

I have the below incomplete code,

Rich (BB code):
Private Sub worksheet_change(ByVal target As Range)

Dim TRowNum As Integer

TRowNum = target.Row

If WorksheetFunction.Countif(Range("B" & trownum & ":" "J" & trownum )) then

End Sub
The bolded line is where I get the error.

Can somebody tell me why?

Thanks
You don't have an argument in the countif function to indicate what the counting criterion is. This line should look like this if, for example, Range("A2") contains the criterion:
Rich (BB code):
If WorksheetFunction.CountIf(Range("B" & TRowNum, "J" & TRowNum), Range("A2")) > 0 Then
 

Watch MrExcel Video

Forum statistics

Threads
1,132,823
Messages
5,655,478
Members
418,205
Latest member
jacc99

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