0

I have a process that builds a cell with a calculation of different values

Val_1 = [A1]
Val_2 = [A2]
[E1] = "=-" & Val_1 & " -" & Val_2

This builds a formula so that the users can see how the output is calculated for example

E1 =-123 -234

I have this VBA code running correctly in UK, but when the process runs in Germany it causes an error: Anwendungs- oder objektdefinierter Fehler

I tried different things but it didn't work. For example using [E1].Formula or adding a character in from of the equal ([E1] = "^=-") and then removing it ([E1]= Right([E1], Len([E1]) - 1))

How can I make it work in Germany?

Selrac
  • 2,203
  • 9
  • 41
  • 84

2 Answers2

0

Maybe you could try concatenating with Application.WorksheetFunction.CONCATENATE(). In my experience, Excel functions are interpreted well between different locales.

EDIT: Alternatively, this post should help setting up a simple if statement after determining the locale: VBA for Excel 2010/2013 - How to identify the system locale

malvoisen
  • 158
  • 7
0

Try, please:

   Dim Val_1 As Long, Val_2 As Long
   Val_1 = Range("A1")
   Val_2 = Range("A2")
   Range("E1").Formula = "=-" & Val_1 & " -" & Val_2

It will work in any installation...

FaneDuru
  • 38,298
  • 4
  • 19
  • 27
  • I tried it, but it doesn't work when Application.LanguageSettings.LanguageID(msoLanguageIDUI) = 1031 – Selrac Mar 30 '20 at 13:03
  • @Selrac: Try also defining `Val_1` and `Val_2` in the same way. it should work. In fact, I will adapt the answer... – FaneDuru Mar 30 '20 at 13:20