VBA Code for Number Format - Run-time error '1004' Unable to set the Number Format property of the Range class

OilEconomist

Active Member
Joined
Dec 26, 2016
Messages
421
Office Version
  1. 2019
Platform
  1. Windows
Hello and thanks in advance for any assistance you can provide. Via Google search I have searched this forum and others, but my sheet is not protected and this code has previously worked I just can't find where I have used it previously.

Why am I getting the error "Run-time error '1004' Unable to set the Number Format property of the Range class" for the following line:

VBA Code:
Range("C" & i).NumberFormat = "[>=1000000] #,##0.0,,""m"";[>0] #,##0.0,""k"

in the following code and how do I fix it?

VBA Code:
Public Sub TestNF()
 Dim i As Long
 i = 71
 Range("C" & i).Value = 12345684
Range("C" & i).NumberFormat = "[>=1000000] #,##0.0,,""m"";[>0] #,##0.0,""k"
End Sub


But why do I not get the same error in the following code:

VBA Code:
Public Sub TestNF()
 Dim i As Long
 i = 71
 Range("C" & i).Value = 12345684
 Range("C" & i).NumberFormat = "#,##0.00"
End Sub

when I use the following line of code instead
VBA Code:
Range("C" & i).NumberFormat = "#,##0.00"

Once again thanks for your assistance.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You're missing a closing quote mark at the end of the offending line (added below).

Range("C" & i).NumberFormat = "[>=1000000] #,##0.0,,""m"";[>0] #,##0.0,""k"""
 
Upvote 0
Solution

Forum statistics

Threads
1,214,965
Messages
6,122,499
Members
449,089
Latest member
Raviguru

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