I have a user form with three things:
Two combo boxes and a command Box
The first combo box just uses a range of different products from the ws.
The second combobox are numbers 0-100 in increments of 5. (values I want to assign)
Lastly my command box is what I want this user form to do, which is:
Find value in first combo box match with string in ws, take number in second command box and offset by 28 columns, and input number in that column. Close userform when finished.
Heres my poor coding so far:
Private Sub UserForm_Initialize()
ComboBox1.RowSource = "A3:A163"
With ComboBox2
.AddItem "95"
.AddItem "90"
.AddItem "85"
.AddItem "80"
.AddItem "75"
.AddItem "70"
.AddItem "65"
.AddItem "60"
.AddItem "55"
.AddItem "50"
.AddItem "45"
.AddItem "40"
.AddItem "35"
.AddItem "30"
.AddItem "25"
End With
End Sub
Private Sub CommandButton1_Click()
Dim ws As Worksheet: Set ws = ActiveWorkbook.Sheets("Balance Sheet")
Dim rng As Range, dFind As Range
Dim c As Control, t As Control
For Each c In Me.Controls
If TypeName(c) = "ComboBox" Then
If Me.ComboBox1.Value = vbNullString Then Exit Sub
If Me.ComboBox1.Value > 0 Then
For Each t In Me.Controls
If TypeName(t) = "TextBox" Then
If Me.TextBox1.Value = vbNullString Then Exit Sub
If Me.TextBox1.Value > 0 Then
Set rng = Application.Intersect(ws.UsedRange, ws.Range("A1").CurrentRegion.Offset(1))
Set dFind = rng.Columns(1).Find(DateValue(TextBox1.Value), , xlValues, xlWhole)
If Not dFind Is Nothing Then
TextBox2.Value = dFind.Offset(0, ComboBox1.Value).Value
Exit Sub
End If
End If
End If
Next t
End If
End If
Next c
End Sub
Thanks in advance!!
Bookmarks