Hi,
I use this userform that works great on the sheet named PRODUCTs that we type our product names directly into column F.
I'm trying to use it on another sheet named ADJUSTMENTS and can't get it to input the values entered in the userform onto that sheet. I've tracked down what I believe to be the issue... on the sheet ADJUSTMENTS the product names in column F are not entered directly. They are pulled from the sheet named PRODUCTs using
I've changed the sheet name in the code to ADJUSTMENTS, and the userform launches fine and the products in Column F are populated in the combobox, but when I submit a value nothing happens. I'm lost on what else needs to be changed to get the userform to work on the sheet ADJUSTMENTS.
Any guidance would be greatly appreciated.
Thank you!
I use this userform that works great on the sheet named PRODUCTs that we type our product names directly into column F.
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 = CDbl(TextBox1.Value)
Else
TextBox1.Value = CDbl(rngFound.Offset(0, 1))
End If
End If
End Sub</code>
I'm trying to use it on another sheet named ADJUSTMENTS and can't get it to input the values entered in the userform onto that sheet. I've tracked down what I believe to be the issue... on the sheet ADJUSTMENTS the product names in column F are not entered directly. They are pulled from the sheet named PRODUCTs using
Code:
=IF(PRODUCTs!F5=0," ",PRODUCTs!F5)
=IF(PRODUCTs!F6=0," ",PRODUCTs!F6)
=IF(PRODUCTs!F7=0," ",PRODUCTs!F7)
etc...
I've changed the sheet name in the code to ADJUSTMENTS, and the userform launches fine and the products in Column F are populated in the combobox, but when I submit a value nothing happens. I'm lost on what else needs to be changed to get the userform to work on the sheet ADJUSTMENTS.
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("ADJUSTMENTS")
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("ADJUSTMENTS")
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 = CDbl(TextBox1.Value)
Else
TextBox1.Value = CDbl(rngFound.Offset(0, 1))
End If
End If
End Sub</code>
Any guidance would be greatly appreciated.
Thank you!