COuntifs Then

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
Office Version
  1. 2013
Hi, i have been trying to get the following to run, but keeps erroring, effectively if value in range (x,25) is contained in Range "i;I") i want "NA Protection" in (X,18), othereise blank

FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To FinalRow
cells(X,18)= If (Application.WorksheetFunction.CountIfs(Worksheets("Non Advised").Range("I:I"), Worksheets("summary").Range(x, 25) > 0) Then Cells(x, 18).Value = "NA Protection" Else Cells(x, 18).Value = "")
Next x

Have put if at the start ,but it always highlighs u to "then" whatever i try.

Any ideas?
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try
Code:
For x = 2 To finalrow
If Application.CountIfs(Worksheets("Non Advised").Range("I:I"), Worksheets("summary").Range(x, 25) > 0) Then Cells(x, 18).Value = "NA Protection" Else Cells(x, 18).Value = ""
Next x
 
Upvote 0
thanks fluff, it still does not like this part.
If Application.CountIfs(Worksheets("Non Advised").Range("I:I"), Worksheets("Summary").Range(x, 25) > 0) Then

error is Application-defined or object defined error

Have checked the worksheet names, all correct.

I can just record it, its just lot cleaner to do it this way keeps the workbook free of formula's
 
Upvote 0
This
Code:
Range(x, 25)
should be Cells not Range
 
Upvote 0
This
Code:
Range(x, 25)
should be Cells not Range

Hi, so changed to cells and now code runs, but does not return any results,

For x = 2 To FinalRow
If Application.CountIfs(Worksheets("Non Advised").Range("I:I"), Worksheets("summary").Cells(x, 25) > 0) Then Cells(x, 18).Value = "NA Protection" Else Cells(x, 18).Value = ""
Next x

If I type in the formula =IF(COUNTIFS('Non Advised'!I:I,Summary!Y2)>0,"NA Protection","") for example, it functions correctly.

Any ideas?
 
Upvote 0
How about
Code:
For x = 2 To FinalRow
If Application.CountIfs(Worksheets("Non Advised").Range("I:I"),  Worksheets("summary").Cells(x, 25)) > 0 Then Cells(x, 18).Value = "NA  Protection" Else Cells(x, 18).Value = ""
Next x
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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