Use formula in cell loop

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,404
Office Version
  1. 2016
Platform
  1. Windows
How can I use a cell address in a formula within a range loop?

I've tried the below but it doesn't work;

Code:
For Each cell In Range("B3:B18")
If cell.Value <> 0 Then
cell.Offset(0, 1).Formula = "=IF(Cell="""","""",COUNTIF(DEPLOYMENTS!$S$2:$S10000,Cell))"
End If
Next
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Untested.
Code:
Cell.Offset(0, 1).Formula = "=IF(" & Cell.Value = "" & ","""",COUNTIF(DEPLOYMENTS!$S$2:$S10000," & Cell.Value & "))"
 
Upvote 0
Thanks Joe - doesn't work I'm afraid, I get 'FALSE' as a result.
 
Upvote 0
What is the working formula in C3 if B3 is populated and you typed it in manually?
 
Last edited:
Upvote 0
Try
Code:
cell.Offset(0, 1).Formula = "=IF(" & cell.Address & "= """" ,"""",COUNTIF(pcode!$S$2:$S10000," & cell.Address & "))"
 
Upvote 0
Fluff,

Thanks, that works, though the 'pcode' part threw me slightly!

Thank you to all that replied.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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