Placing actual formula in a cell not it's result using vba

aRush113

New Member
Joined
Nov 10, 2023
Messages
14
Office Version
  1. 2019
Platform
  1. Windows
I'm trying to place this formula
Excel Formula:
=IF(COUNTIF($D$1:D1,"="&D1)>1,TRUE,FALSE)
in a cell. I'm using
VBA Code:
Range("F1").Formula = "=IF(COUNTIF($D$1:D1,"="&D1)>1,TRUE,FALSE)"
but instead of the formula it's placing it's result.

This formula will eventually be copied down to the last row of a variable $D$1:D...nth row.

Thanx for your preciuos help.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi aRush113. I think this formula does the same thing and it does insert. HTH. Dave
Code:
Range("F1").Formula = "=IF(COUNTIF($D$1:D1,D1)>1,TRUE,FALSE)"
 
Upvote 0
Solution
You don't actually need the IF, you can just use
VBA Code:
Range("F1").Formula = "=COUNTIF($D$1:D1,""=""&D1)>1"
 
Upvote 0
Hi aRush113. I think this formula does the same thing and it does insert. HTH. Dave
Code:
Range("F1").Formula = "=IF(COUNTIF($D$1:D1,D1)>1,TRUE,FALSE)"
Thanx for the quick reply, as it seems my error was putting the ""=""& part.:sleep: Stupid me. :rolleyes:

Fluff your solution works too.

Thanx to the both of you.
Always kind and helpful.
 
Upvote 0
Glad we could help & thanks for the feedback.

It is not the =D1 part that was wrong, it's just that you need to double-up the quotes as I showed.
 
Upvote 0

Forum statistics

Threads
1,215,335
Messages
6,124,326
Members
449,155
Latest member
ravioli44

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