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!!
 
If the number occurs multiple times then the textbox will have the value from col F for the last occurrence.
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
If the number occurs multiple times then the textbox will have the value from col F for the last occurrence.
What is i use the following?

VBA Code:
If Me.ComboBox11.Value = ws.Cells(i, "b").Text And Me.ComboBox7.Value = ws.Cells(i, "a").Text Then
 
Upvote 0
What is i use the following?

VBA Code:
If Me.ComboBox11.Value = ws.Cells(i, "b").Text And Me.ComboBox7.Value = ws.Cells(i, "a").Text Then
which still appears to bring back the incorrect value
 
Upvote 0
That should get the last occurrence of when when combo11 = col B & combo7 =col A
 
Upvote 0
That should get the last occurrence of when when combo11 = col B & combo7 =col A
its not pulling that though. its pulling the last row in column h

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("a" & Rows.Count).End(xlUp).Row

For i = 2 To lastrow

If Me.ComboBox11.Value = ws.Cells(i, "b").Text And Me.ComboBox7.Value = ws.Cells(i, "a").Text Then

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

End If

Next i

End Sub
 
Upvote 0
Final Code

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("a" & Rows.Count).End(xlUp).Row

For i = 2 To lastrow

If Me.ComboBox11.Text = ws.Cells(i, "b").Text And Me.ComboBox7.Text = ws.Cells(i, "a").Text _
And Me.ComboBox8.Text = ws.Cells(i, "c").Text And Me.ComboBox10.Text = ws.Cells(i, "e").Text Then

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

End If

Next i

End Sub

Thank you Fluff!!
 
Upvote 0
Solution
Glad you sorted it & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,615
Messages
6,120,538
Members
448,970
Latest member
kennimack

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