Run-time error '1004': Unable to set the NumberFormat property of the Range class

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I am currently using a password protected spreadsheet that someone else created at my work. The problem that I am having is that I can't format a cell with the number format option on the Home tab. It is greyed out.

I have a userform that the user will enter in a product code in text box. When the user exits that text box, it opens another workbook that contains the UCL-LCL values for that product code. The problem that I am having is if the value for a particular product code UCL-LCL value is 99.0-103.0, it only returns 99-103 and leaves off the zeros. However, if the values is 99.3-103.6 it will return those values. I need the number from the userform to be formatted with VBA to where it displays one decimal place. Thank You.

Code:
Private Sub TxtBxBlkBlnd_Exit(ByVal Cancel As MSForms.ReturnBoolean)    
    'Declares variable names
    Dim sPath As String, sFile As String
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim foundBulk As Range
    Dim strBulk As String
    Dim strRng1 As String
    Dim strRng2 As String
    
    
'    Workbooks("F-103-04 Exh E-Bulk MT-Pkg Prod Theoretical Yield Report-Rev004.xlsx").Worksheets("Exhibit E Bulk mt").Hide
    
    'Opens Yield Limit Log sheet subroutine
    Call openYieldLimitLogs
        
    strBulk = TxtBxBlkBlnd.Value
    
    Set foundBulk = ActiveSheet.Range("B3", Range("B" & Rows.Count).End(xlUp)).Find(strBulk)
    
    If foundBulk Is Nothing Then
        MsgBox ("Nothing found")
    Else
        Application.ScreenUpdating = False
        strRng1 = Cells(foundBulk.Row, 5).Value
        strRng2 = Cells(foundBulk.Row, 6).Value
        Workbooks("2019 Yield Limits Log.xlsx").Close
        Call openWorkbookLocation
        Worksheets("Exhibit E Bulk mt").Activate

        Worksheets("Exhibit E Bulk mt").Range("F50") = strRng1 & " - " & strRng2


        Application.ScreenUpdating = True
    End If
    
End Sub
I've even tried adding the following code
Code:
 Worksheets("Exhibit E Bulk mt").Range("F50").Select
        Selection.NumberFormat = "0.0"
in between
Code:
Worksheets("Exhibit E Bulk mt").Activate[B]CODE ADDED HERE[/B]
        Worksheets("Exhibit E Bulk mt").Range("F50") = strRng1 & " - " & strRng2
but I get a Runtime error '1004':Unable to set the NumberFormat property of the Range class. I need the NumberFormat added to strRng1 and strRng2 to show one decimal point. I hope my explanation makes sense. Thank you.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Not clear what info you're trying to format? U can do this...
Code:
strRng1 = Cstr(Format(Cells(foundBulk.Row, 5).Value, "###0.0"))
HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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