Populate a textbox based on combobox selection and other conditions

DanSMT

Board Regular
Joined
Sep 13, 2019
Messages
203
Office Version
  1. 2013
Platform
  1. Windows
All,

Im trying to figure out why the following code is not working... Im trying to pull data from a sheet into a textbox based on the change of a combobox. See below;

VBA Code:
Private Sub ComboBox10_Change()

Dim i As Long
Dim lastrow As Long
Dim ws As Worksheet

Me.TextBox13 = ""

Set ws = Sheets("paste log")

lastrow = ws.Range("f" & Rows.Count).End(xlUp).Row

For i = 2 To lastrow

If Me.ComboBox11.Value = ws.Cells(i, "b") & Me.ComboBox8.Value = ws.Cells(i, "c") Then

Me.TextBox13 = ws.Cells(i, "f").Text

End If

Next i

End Sub


If i run the following code the code runs, but only brings the latest date in relation to a "NA" line on the spreadsheet and then stops.


VBA Code:
Private Sub ComboBox10_Change()

Dim i As Long
Dim lastrow As Long
Dim ws As Worksheet

Me.TextBox13 = ""

Set ws = Sheets("paste log")

lastrow = ws.Range("f" & Rows.Count).End(xlUp).Row

For i = 2 To lastrow

If Me.ComboBox10.Value = ws.Cells(i, "e") Then

Me.TextBox13 = ws.Cells(i, "f").Text

End If

Next i

End Sub

Any help would be greatly appreciated. Thanks!!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You need to replace the & with And on this line
VBA Code:
If Me.ComboBox11.Value = ws.Cells(i, "b") & Me.ComboBox8.Value = ws.Cells(i, "c") Then
 
Upvote 0
Thanks Fluff.

However, I decided to revert back to the single line if statement and its not working if I try to look at a different column. Not quite understanding why,

VBA Code:
Private Sub ComboBox10_Change()

Dim i As Long
Dim lastrow As Long
Dim ws As Worksheet

'Me.TextBox13 = ""

Set ws = ThisWorkbook.Sheets("paste log")

lastrow = ws.Range("b" & Rows.Count).End(xlUp).Row

For i = 2 To lastrow

If Me.ComboBox11.Value = ws.Cells(i, "b") Then

Me.TextBox13 = ws.Cells(i, "f").Value

End If

Next i

End Sub

Changing from combobox 10 and column e to combobo11 and column b does not show anything in the textbox.
 
Upvote 0
What sort of values do you have in the combo?
 
Upvote 0
just noticed the "b" in the lastrow statement. fixed that, but still doesnt work.
 
Upvote 0
numbers, but they are part of a cascading combobox setup some times they are numbers sometimes they are letters
 
Upvote 0
In that case try
VBA Code:
If Me.ComboBox11.Value = ws.Cells(i, "b").Text Then
 
Upvote 0
In that case try
VBA Code:
If Me.ComboBox11.Value = ws.Cells(i, "b").Text Then
this is pulling the date in the last row. not the date from the same row. I must have made a mistake elsewhere
 
Upvote 0
Will the combo11 value appear just onve in col B, or multiple times?
 
Upvote 0
Will the combo11 value appear just onve in col B, or multiple times?
It could appear multiple times. Currently I only have a single occurance entered. Then intent is to have multiple entries
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,567
Members
449,171
Latest member
jominadeo

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