Hi,
New here and I took over using a workbook at my company and I'm trying to learn VBA to make some changes. One of the issues is with this userform code that we use to add part order quantities, it works great except for it only inputs a whole number in the cells. As an example if I input 2.5 as a quantity it will round it to 3 and input 3.00. It's not a formatting issue, as the cells are formatted to out put two decimal places.
I've been trying to change the textbox1 values but have not had any luck getting it to input decimals into the sheet. Any help getting the code to do this would be greatly appreciated.
New here and I took over using a workbook at my company and I'm trying to learn VBA to make some changes. One of the issues is with this userform code that we use to add part order quantities, it works great except for it only inputs a whole number in the cells. As an example if I input 2.5 as a quantity it will round it to 3 and input 3.00. It's not a formatting issue, as the cells are formatted to out put two decimal places.
I've been trying to change the textbox1 values but have not had any luck getting it to input decimals into the sheet. Any help getting the code to do this would be greatly appreciated.
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Option Explicit
Private Sub UserForm_Initialize()
Dim rngSource As Range
Dim rngMyCell As Range
Dim wsMySheet As Worksheet
Set wsMySheet = Sheets("PRODUCTs")
wsMySheet.Range("$F$5:$F$" & wsMySheet.Cells(Rows.Count, "F").End(xlUp).Row).AutoFilter Field:=1, Criteria1:="<>", Operator:=xlFilterValues
Set rngSource = wsMySheet.Range("F5:F" & wsMySheet.Cells(Rows.Count, "F").End(xlUp).Row).SpecialCells(xlCellTypeVisible)
ComboBox1.Clear
For Each rngMyCell In rngSource
ComboBox1.AddItem rngMyCell.Value
Next rngMyCell
wsMySheet.AutoFilterMode = False 'Remove above filter
End Sub
Private Sub ComboBox1_Change()
Call SetQTY(False)
End Sub
Private Sub CommandButton1_Click()
Call SetQTY(True)
End Sub
Sub SetQTY(blnOutputToSheet As Boolean)
Dim rngFound As Range
Dim wsMySheet As Worksheet
Dim lngLastRow As Long
Set wsMySheet = Sheets("PRODUCTs")
lngLastRow = wsMySheet.Cells(Rows.Count, "F").End(xlUp).Row
Set rngFound = wsMySheet.Range("F5:F" & lngLastRow).Find(What:=CStr(ComboBox1.List(ComboBox1.ListIndex)), LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If ComboBox1.ListIndex <> -1 And Not rngFound Is Nothing Then
If blnOutputToSheet = True Then
rngFound.Offset(0, 1).Value = CLng(TextBox1.Value)
Else
TextBox1.Value = CLng(rngFound.Offset(0, 1))
End If
End If
End Sub</code>