Unable to set the NumberFormat property of the Range class; Run-time error “1004”

dilshod_k

Board Regular
Joined
Feb 13, 2018
Messages
79
I have an excel workbook which downloads historical stocks price data.
The VBA code has been working without any problems for at least couple of years.
Today I get error message:
Run-time error “1004” - Unable to set the NumberFormat property of the Range class

part of VBA code as it follows below:

Set myRange = ThisWorkbook.Worksheets("Control").Range("ControlExtractDataNumberHeading")
Set myRange = Range(myRange, myRange.Offset(0, intYPEAdjustedClosePrice - 3))
Set myRange = Range(myRange, myRange.End(xlDown))
myRange.NumberFormat = Application.International(xlCurrencyCode) & "#,##0.00" - ERROR MESSAGE AT THIS STEP!!!
myRange.Value = myRange.Value2

I'm using Microsoft Office Professional Plus 2016
Windows 10

Thanks in advance for suggestions.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I get no error when I execute:

Range("a1:a10").NumberFormat = Application.International(xlCurrencyCode) & "#,##0.00"

So my guess is: (a) you unconsciously corrected the problem when you posted the code; or (b) VBA is misleading you or you are otherwise misinterpreting where the error occurs; or (c) myRange is not what you think it is, perhaps because (if) you executed On Error Resume Next beforehand. (But arguably, that also would have "hidden" the error that you got, unless you also executed On Error GoTo 0 beforehand.)

I suggest that you enter the following statement after each Set statement:

Debug.Print myRange.Address(True,True,external:=True)

After execution, press ctrl+G to see the Debug.Print output in the Immediate Window.

If the problem persists, also execute Debug.Print Application.International(xlCurrencyCode), and include all Debug.Print output in a follow-up posting.

PS.... I wonder if another possible source of the VBA error is that you have "too many" formats in the Excel file. What happens if you try to do the same thing manually in Excel? (In the same Excel file, of course.)
 
Last edited:
Upvote 0
Any merged cells in the range?

No merged cells.
I think I found the problem. Recently I changed Windows Region/Format settings to English (Europe), apparently that was the cause of the problem. As soon as I changed it back to English (United States) error message disappeared. :biggrin: Thanks for an attempt to help anyway.
3078161072
 
Last edited:
Upvote 0
I get no error when I execute:

Range("a1:a10").NumberFormat = Application.International(xlCurrencyCode) & "#,##0.00"

So my guess is: (a) you unconsciously corrected the problem when you posted the code; or (b) VBA is misleading you or you are otherwise misinterpreting where the error occurs; or (c) myRange is not what you think it is, perhaps because (if) you executed On Error Resume Next beforehand. (But arguably, that also would have "hidden" the error that you got, unless you also executed On Error GoTo 0 beforehand.)

I suggest that you enter the following statement after each Set statement:

Debug.Print myRange.Address(True,True,external:=True)

After execution, press ctrl+G to see the Debug.Print output in the Immediate Window.

If the problem persists, also execute Debug.Print Application.International(xlCurrencyCode), and include all Debug.Print output in a follow-up posting.

PS.... I wonder if another possible source of the VBA error is that you have "too many" formats in the Excel file. What happens if you try to do the same thing manually in Excel? (In the same Excel file, of course.)


I think I found the problem. Recently I changed Windows Region/Format settings to English (Europe), apparently that was the cause of the problem. As soon as I changed it back to English (United States) error message disappeared. :biggrin:Thanks for advice anyway.
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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