Display Max Value in a Textbox from a Database Column that Matches Multiple Criteria in Combo Box

aroig07

New Member
Joined
Feb 26, 2019
Messages
42
Hi !!

I am having some problems with this macro I am working on. I am trying to look in a Database what is the maximum number in a column that matches 3 variables (2 in combo boxes = student name and module name, and one is a write in as you see in the example bronze). This max value should show up in a textbox inside a userform when the combo boxes are changed. PLEASE help I have tried everything.


'Automatically input maximum level reached based on the student, module name, and ribbon type entered
Dim d As Long
Dim LastRows As Long
Dim wss As Worksheet

Set wss = Sheets("DataBase")
LastRows = wss.Range("A" & Rows.Count).End(xlUp).Row

For d = 2 To LastRows
If wss.Cells(i, "C").Value = (Me.ComboBox2) And wss.Cells(i, "F").Value = (Me.ComboBox7) And wss.Cells(i, "G").Value = "Bronze" Or _
wss.Cells(i, "C").Value = Val(Me.ComboBox2) And wss.Cells(i, "F").Value = Val(Me.ComboBox7) And wss.Cells(i, "G").Value = "Bronze" Then
Me.TextBox10 = wss.Cells(i, "H").Value
End If

If wss.Cells(i, "C").Value = (Me.ComboBox2) And wss.Cells(i, "F").Value = (Me.ComboBox7) And wss.Cells(i, "G").Value = "Silver" Or _
wss.Cells(i, "C").Value = Val(Me.ComboBox2) And wss.Cells(i, "F").Value = Val(Me.ComboBox7) And wss.Cells(i, "G").Value = "Silver" Then
Me.TextBox12 = wss.Cells(i, "H").Value
End If

If wss.Cells(i, "C").Value = (Me.ComboBox2) And wss.Cells(i, "F").Value = (Me.ComboBox7) And wss.Cells(i, "G").Value = "Gold" Or _
wss.Cells(i, "C").Value = Val(Me.ComboBox2) And wss.Cells(i, "F").Value = Val(Me.ComboBox7) And wss.Cells(i, "G").Value = "Gold" Then
Me.TextBox11 = wss.Cells(i, "H").Value
End If
Next d
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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