Good aftrnoon and thank you in advance for any help.
I have created a code that I am using in a combobox to pull information into my userform from a worksheet. I am using the match function for a specific worksheet. What I would like to do, is be able to use the match function to pull the information into my userform based on the the current active worksheet, instead of having to specify the worksheet and creating a userform for each month (which right now is the only way I can think of because I can't seem to figure that part out
My workbook is set up by month. Here is the code I created. Any help would be much apprecitated. TY...Sandy
Dim testales As Long
Dim x As Variant
Dim Response As VbMsgBoxResult
Dim lRow As Long
Dim ctlinfo As Control
Dim C As Range
txtempno1 = Sheets("Master").Range("A" & gmsales1.ListIndex + 2)
txtsales1 = Sheets("Master").Range("B" & gmsales1.ListIndex + 2)
txtlocation1 = "GM"
Sheets("April").Activate
testsales = gmsales1.Value
x = Application.Match(testsales, Worksheets("April").Range("c1:c17"), 0)
If IsError(x) Then
MsgBox "No current record exsist, continue recording new record.", vbInformation + vbOKOnly
Me.txtunits1.Enabled = True
Me.txtpvrtot1.Enabled = True
Me.txtemp1.Enabled = True
Else
Me.txtunits1.Enabled = False
Me.txtpvrtot1.Enabled = False
Me.txtemp1.Enabled = False
testsales = gmsales1.Value
With Sheets("April")
' row determination
Ctr = Application.Match(testsales, Worksheets("April").Range("c1:c17"), 0)
If Application.Match(testsales, Worksheets("April").Range("c1:c17"), 0) Then
' populate TextBox2
Me.txtunits1.Text = Application.Index(.[d:d], Ctr, 0)
Me.txtpvrtot1.Text = Application.Index(.[f:f], Ctr, 0)
Response = MsgBox("A record already exisit for: " & gmsales1.Value & vbCrLf & ("Do you wish to edit record."), vbQuestion + vbYesNoCancel)
If Response = vbYes Then
gmfrmedit.Show
ElseIf Response = vbNo Then Exit Sub
For Each C In Range("A1:A17" & Cells(Rows.Count, "A").End(xlUp).Row)
If Not IsError(C) Then
If C.Value = "True" Then
Range("A" & C.Row & ":G" & C.Row).Interior.ColorIndex = 6
Else
Range("A" & C.Row & ":G" & C.Row).Interior.ColorIndex = xlNone
End If
End If
Next C
End If
End If
End With
End If
End Sub
Bookmarks