0

I am trying to write a formula stored in a string to a cell in Excel using VBA. However, I keep getting a runtime error 1004 when executing the code.

Dim fmla As String    
fmla = "SUMIF(" & firstBucketLetter & "$" & firstRowCountryGroup & ":" & firstBucketLetter & "$" & lastRowCountryGroup & ";$" & columnPlanningSheetStartStr & firstRowGroup & ";" & firstBucketLetter & "$" & firstRow & ":" & firstBucketLetter & "$" & lastRow & ")"
Cells(firstRowGroup, firstBucket).formula = "=" & fmla

I have also tried the below, but doesn't seem to work either...

fmla = "=SUMIF(" & firstBucketLetter & "$" & firstRowCountryGroup & ":" & firstBucketLetter & "$" & lastRowCountryGroup & ";$" & columnPlanningSheetStartStr & firstRowGroup & ";" & firstBucketLetter & "$" & firstRow & ":" & firstBucketLetter & "$" & lastRow & ")"
Cells(firstRowGroup, firstBucket).formula = fmla

When I remove the = sign in the string, then it will write the string without problems and give the following result in the cell: SUMIF(E$55:E$68;$C71;E$12:E$25)

Dim fmla As String    
fmla = "SUMIF(" & firstBucketLetter & "$" & firstRowCountryGroup & ":" & firstBucketLetter & "$" & lastRowCountryGroup & ";$" & columnPlanningSheetStartStr & firstRowGroup & ";" & firstBucketLetter & "$" & firstRow & ":" & firstBucketLetter & "$" & lastRow & ")"
Cells(firstRowGroup, firstBucket).value = fmla

What am I doing wrong?

Thanks for your help.

Kind regards Jan

Jan V
  • 7
  • 2

0 Answers0