Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- 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.
I've even tried adding the following code
in between
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.
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
Code:
Worksheets("Exhibit E Bulk mt").Range("F50").Select
Selection.NumberFormat = "0.0"
Code:
Worksheets("Exhibit E Bulk mt").Activate[B]CODE ADDED HERE[/B]
Worksheets("Exhibit E Bulk mt").Range("F50") = strRng1 & " - " & strRng2