2

Can anyone tell me why it doesn't work? I have look trough all the topics: concatenating variables, concatenating strings, etc. I think the main reason is the "(" character but I haven't found a way to escape it.

The result should return =DATE(2018;5;31)+TIME(15;40;0) , I mean, show the current day and time. Thank you very much.

Sub intertformula()

Dim repYear As Integer
Dim repMonth As Integer
Dim repDay As Integer
Dim repHour As Integer
Dim repMin As Integer

repYear = Year(Date)
repMonth = Month(Date)
repDay = Day(Date)
repHour = Hour(Time)
repMin = Minute(Time)

Range("H3").Formula = "=DATE(" & repYear & ";" & repMonth & ";" & repDay & ")+TIME(" & repHour & ";" & repMin & ";0)"
Cris
  • 21
  • 1
  • 2
    The DATE and TIME formulas require commas... right? – Jacob H May 31 '18 at 13:08
  • 4
    Independent of locale settings, in `VBA` `Range.Formula` always needs US locale formulas. So the semicolon needs to be comma. `Range("H3").Formula = "=DATE(" & repYear & "," & repMonth & "," & repDay & ")+TIME(" & repHour & "," & repMin & ",0)"`. `Range.FormulaLocal` would be locale dependent, but I would not recommend using this. – Axel Richter May 31 '18 at 13:09
  • 2
    .Formula requires commas. Use .FormulaLocal if you absolutely require semi-colons as regional list separators. –  May 31 '18 at 13:10

0 Answers0