Formula inserted by macro doesn't work

Hubs

New Member
Joined
Sep 10, 2021
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
Hi everyone

I'm about to give up! I want to write, in a cell, the "greater or equal" or the "lesser or equal" signs, through a macro.
I've found the Excel formula =UNICAR(8804) for =< (and =UNICAR(8804) for >=). If i write it by hand, it's OK. but my vba is not OK.

ActiveCell.Offset(x,y).Formula R1C1 = "=UNICAR(8804)" results in a #NAME?

I've seen that UNICAR(xxx) neds the "xxx" to be text, and that the cell should be formatted in text, and that formulas should be written in english, so I ended up with the rather not straightforward formula :
ActiveCell.Offset(x,y).FormulaR1C1 = "=UNICAR(DROITE(TEXTE(8804;10);4))"
and
ActiveCell.Offset(x,y).FormulaR1C1 = "=UNICAR(RIGHT(TEXT(8804;10);4))"

Both bring a box with "execution error '1004': Error defined by the application or the object" (I'm translating from the French, but it should be something like that)
If I write the french version by hand in the cell, it's OK.


Question : What should be the proper formula in the macro ?

many thanks for your help

Hubert
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
How about
VBA Code:
ActiveCell.Offset(x,y).Formula = "=UNICAR(8804)"
 
Upvote 0
If i write it by hand, it's OK. but my vba is not OK.
If that is true, then try this:
Turn on your Macro Recorder, and record yourself entering the formula into a cell manually (which should work, as you said).
Then turn off the Macro Recorder, and view the code you just recorded. This should show you how VBA wants to see it.
Make the change to your code to match that, and see if that works when you then run the code.
 
Upvote 0
I'm not used to the interface...

Good idea, but I get the #NAME again (I did try that option, too)

I even tried t use ActiveCell.Offset(x.y).Value = "UNICAR(8804)" ...
 
Upvote 0
Just realised you are missing an H it should be UNICHAR
 
Upvote 0
Solution
If that is true, then try this:
Turn on your Macro Recorder, and record yourself entering the formula into a cell manually (which should work, as you said).
Then turn off the Macro Recorder, and view the code you just recorded. This should show you how VBA wants to see it.
Make the change to your code to match that, and see if that works when you then run the code.
Bingo ! I need to write ="UNICHAR(8804)"

Many thanks
 
Upvote 0
what is unicar

i can only find unichar
 
Upvote 0
Just realised you are missing an H it should be UNICHAR
You are right. I had no clue that UNICAR would need to be translated, too. Many thanks. It works ! Yeepee !
 
Upvote 0
When using VBA to insert a formula you need to use the English version of the function. Another possibility (that I cannot test) is to use your language version of the function but use .FormulaLocal
 
Upvote 0

Forum statistics

Threads
1,214,636
Messages
6,120,666
Members
448,977
Latest member
moonlight6

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