I have a function in a userform I'm using to lookup a row within a worksheet to extract 3 cell values once the proper row has been matched. I figure I needed to place the sub within the last value that's triggered.
Private Sub txtCompCode_Change()
Dim recRow As Range
Set recRow = MatchSalaryRange(Worksheets("Salary Ranges").Range("A1").CurrentRegion, _
Me.cmbPosition.Value, _
txtCompCode.Text)
If recRow Is Nothing Then Exit Sub
With recRow.EntireRow
.Cells(4).Value = Me.txtMIN.Text
.Cells(5).Value = Me.txtMID.Text
.Cells(6).Value = Me.txtMAX.Text
End With
End Sub
Function MatchSalaryRange(tablerange As Range, lPosition, lCompCode) As Range
Dim rw As Range
For Each rw In tablerange.Rows
If CStr(rw.Cells(2).Value) = CStr(lPosition) Then
If rw.Cells(3).Value = lCompCode Then
Set MatchSalaryRange = rw
Exit Function
End If
End If
Next rw
End Function
it first references a job title in a text box and then a compensation code in another text box. then it locates the row, supposed to pull columns D:E in order to populate the Min/Mid/Max text boxes, but it's not doing so.
Any ideas?
EDIT: based on this after the right text box in yellow is selected, it should trigger the function for the red text boxes below.
If
in your function? – Tim WilliamscmbPosition
contain, what doestxtCompCode
contain. As @TimWilliams suggested, doing some debugging should tell you more. – NicolastxtCompCode
. TheChange
event triggers as soon as the value of the textbox changes, perhaps one of the other events is better used,AfterUpdate
for example (though I need to know more about the use case). Is store number another textbox which automatically fills thetxtCompCode
textbox? – Nicolasset matchsalaryrange = rw
part, but it's saying it's set to nothing – NidenK