Change userform textbox value based on combox value

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi All,

I have a userform and I want certain textboxes to change their value dependent on the combobox value.
The combobox can show 1st - 4th and I want two text boxes within the userfor to base their values on different cells within my spreadsheet. At the moment I have this, but it doesn't work:

Private Sub CBPrototypes_Change()

If CBPrototypes = "1st" Then
frmcaseaccepted.TBPlanner = Cells(Target.Row, 76)
frmcaseaccepted.CBEngineers = Cells(Target.Row, 81)
End If

If CBPrototypes = "2nd" Then
frmcaseaccepted.TBPlanner = Cells(Target.Row, 82)
frmcaseaccepted.CBEngineers = Cells(Target.Row, 86)
End If

If CBPrototypes = "3rd" Then
frmcaseaccepted.TBPlanner = Cells(Target.Row, 87)
frmcaseaccepted.CBEngineers = Cells(Target.Row, 91)
End If

If CBPrototypes = "4th" Then
frmcaseaccepted.TBPlanner = Cells(Target.Row, 92)
frmcaseaccepted.CBEngineers = Cells(Target.Row, 96)
End If

End Sub


The userform is opened by right clicking on the row.

Hope I've supplied enough information.

Thanks in advance,

Mike
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Nevermind I worked it out, just added:

Code:
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Data")
x = Me.LblRow 'current row
    
If CBPrototypes = "1st" Then
frmcaseaccepted.TBPlanner = Cells(x, 76)
frmcaseaccepted.CBEngineers = Cells(x, 81)
End If

Thanks anyway
 
Upvote 0
Hi try

Code:
Private Sub CBPrototypes_Change()
    Dim Index As Integer
    
    Index = Me.CBPrototypes.ListIndex + 1


    Me.TBPlanner = Cells(ActiveCell.Row, Choose(Index, 76, 82, 87, 92))
    Me.CBEngineers = Cells(ActiveCell.Row, Choose(Index, 81, 86, 91, 96))
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top