The 'If' statements although many need to be in two seperate groups, 'if' statements for the plate option and if statements for the profile option.
So if they choose Plate, then select a date and a thickness, your code (which works fine) returns the intersecting value, which is the stock amount on that date in that thickness.
But if the user chooses profile, and not plate, the same code needs to work on the profile sheet the same as it does on the plate tracker.
The code I copied below hasnt copied over showing how the if statements are nested so I'll try and explain a little....
This is the userform, they select palte or profile, date and thickness. Then the 4 text boxes return the values that your code finds.
And for all of the plate thickness's it works. But if the user selects profile, nothing is returned.
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
If ComboBox1.Value = "Plate" Then (When the OK button is pressed the user had two options to select from Plate or Profile. So combobox1.value can be either Plate or Profile. So there are IF statments for the plate option, but then there needs to be IF statements for the profile option.
Sheets("Plate Tracker").Select
If ComboBox3.Value = 2 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("D" & lngRow).Value
TextBox1.Value = Range("T" & lngRow).Value
TextBox3.Value = Range("AJ" & lngRow).Value
TextBox4.Value = Range("AZ" & lngRow).Value
End If
End If
If ComboBox3.Value = 3 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("E" & lngRow).Value
TextBox1.Value = Range("U" & lngRow).Value
TextBox3.Value = Range("AK" & lngRow).Value
TextBox4.Value = Range("BA" & lngRow).Value
End If
End If
If ComboBox3.Value = 4 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("F" & lngRow).Value
TextBox1.Value = Range("V" & lngRow).Value
TextBox3.Value = Range("AL" & lngRow).Value
TextBox4.Value = Range("BB" & lngRow).Value
End If
End If
If ComboBox3.Value = 5 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("G" & lngRow).Value
TextBox1.Value = Range("X" & lngRow).Value
TextBox3.Value = Range("AM" & lngRow).Value
TextBox4.Value = Range("BC" & lngRow).Value
End If
End If
If ComboBox3.Value = 6 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("H" & lngRow).Value
TextBox1.Value = Range("Y" & lngRow).Value
TextBox3.Value = Range("AN" & lngRow).Value
TextBox4.Value = Range("BD" & lngRow).Value
End If
End If
If ComboBox3.Value = 8 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("I" & lngRow).Value
TextBox1.Value = Range("Z" & lngRow).Value
TextBox3.Value = Range("AO" & lngRow).Value
TextBox4.Value = Range("BE" & lngRow).Value
End If
End If
If ComboBox3.Value = 10 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("J" & lngRow).Value
TextBox1.Value = Range("AB" & lngRow).Value
TextBox3.Value = Range("AP" & lngRow).Value
TextBox4.Value = Range("BF" & lngRow).Value
End If
End If
If ComboBox3.Value = 12 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("K" & lngRow).Value
TextBox1.Value = Range("AC" & lngRow).Value
TextBox3.Value = Range("AQ" & lngRow).Value
TextBox4.Value = Range("BG" & lngRow).Value
End If
End If
If ComboBox3.Value = 15 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("L" & lngRow).Value
TextBox1.Value = Range("AD" & lngRow).Value
TextBox3.Value = Range("AR" & lngRow).Value
TextBox4.Value = Range("BH" & lngRow).Value
End If
End If
If ComboBox3.Value = 20 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("M" & lngRow).Value
TextBox1.Value = Range("AE" & lngRow).Value
TextBox3.Value = Range("AS" & lngRow).Value
TextBox4.Value = Range("BI" & lngRow).Value
End If
End If
If ComboBox3.Value = 25 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("N" & lngRow).Value
TextBox1.Value = Range("AF" & lngRow).Value
TextBox3.Value = Range("AT" & lngRow).Value
TextBox4.Value = Range("BJ" & lngRow).Value
End If
End If
If ComboBox3.Value = 30 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("O" & lngRow).Value
TextBox1.Value = Range("AG" & lngRow).Value
TextBox3.Value = Range("AU" & lngRow).Value
TextBox4.Value = Range("BK" & lngRow).Value
End If
End If
If ComboBox3.Value = 35 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("P" & lngRow).Value
TextBox1.Value = Range("AH" & lngRow).Value
TextBox3.Value = Range("AV" & lngRow).Value
TextBox4.Value = Range("BL" & lngRow).Value
End If
End If
If ComboBox3.Value = 40 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("Q" & lngRow).Value
TextBox1.Value = Range("AI" & lngRow).Value
TextBox3.Value = Range("AW" & lngRow).Value
TextBox4.Value = Range("BM" & lngRow).Value
End If
End If
If ComboBox3.Value = 60 Then
If ComboBox2.ListIndex <> -1 Then
lngRow = ComboBox2.ListIndex + 7
TextBox2.Value = Range("R" & lngRow).Value
TextBox1.Value = Range("AJ" & lngRow).Value
TextBox3.Value = Range("AX" & lngRow).Value
TextBox4.Value = Range("BN" & lngRow).Value
End If
End If
(This is the end of the IF statements for the plate option, and again all the code above works as it should.)
If ComboBox1.Value = "Profile" Then
Sheets("Profile Tracker").Select
If ComboBox3.Value = "300-8470" Then
If ComboBox2.ListIndex <> -1 Then
lngRow_pro = ComboBox2.ListIndex + 7
TextBox2.Value = Range("D" & lngRow_pro).Value
TextBox1.Value = Range("M" & lngRow_pro).Value
TextBox3.Value = Range("V" & lngRow_pro).Value
TextBox4.Value = Range("AE" & lngRow_pro).Value
End If
End If
End If
End If
Sheets("User Interface").Select
Range("C35").Select
Application.ScreenUpdating = True