Runtime error 1004

Misca

Well-known Member
Joined
Aug 12, 2009
Messages
1,760
Office Version
  1. 365
Platform
  1. Windows
I'm trying to run a macro that replaces a decimal value in a cell with a formula that refers to that number:
VBA Code:
Dim cell As Range

For Each cell In Selection
    If IsNumeric(cell) Then
        cell.Formula = "=ROUND(" & cell.Value & "*(1+$D$5), 2)"
    End If
Next cell
,
When I run the macro I'm getting "Run-time error '1004': Application-defined or object-defined error". I believe this is because I'm using the Finnish settings in my Excel where the decimal separator is a comma instead of a period. I believe the IsNumeric should make sure VBA understands the numbers as numbers even with the commas but I'm not getting an error if I replace the commas with periods. Is there any way to use the actual cell value regardless of the formatting instead of replacing the "cell.value" with the "Replace(cell.value, ",", ".")" wich to me seems unnecessary for VBA clearly understands the cell value as a number instead of text already.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
This is Excel not VBa. Seems like it is set with "." as the decimal point.
 
Upvote 0
Playing with the below you can set as required


VBA Code:
Sub Seperator()
With Application
    .UseSystemSeparators = False
    .ThousandsSeparator = "."
    Debug.Print [A1].Text
  
    '// Go Back to System
    .ThousandsSeparator = ","
    .UseSystemSeparators = True
    Debug.Print [A1].Text
End With
  
End Sub
 
Upvote 0
If you use FormulaLocal instead (adjusting separators and function names to match what you would actually enter in a cell), it should work with your regional settings.
 
Upvote 0
Solution

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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