![]() |
ComboBox programming not working
If anyone can help?!
Problem I have is that my combobox has values and if you select the lowest value (12) first then any larger value it works fine, but if you select a larger value fisrt then a lower value second, nothing happens. Here is the code I have. Private Sub ComboBox1_Change() If ComboBox1.Value = 12 Then Range ("A8:G49,K8:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 18 Then Range ("A8:G10,K8:Q10").Interior.ColorIndex = 0 And _ Range("A11:G49,K11:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 20 Then Range ("A8:G11,K8:Q11").Interior.ColorIndex = 0 And _ Range("A12:G49,K12:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 24 Then Range ("A8:G13,K8:Q13").Interior.ColorIndex = 0 And _ Range("A14:G49,K14:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 30 Then Range ("A8:G16,K8:Q16").Interior.ColorIndex = 0 And _ Range("A17:G49,K17:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 42 Then Range ("A8:G22,K8:Q22").Interior.ColorIndex = 0 And _ Range("A23:G49,K23:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 54 Then Range ("A8:G28,K8:Q28").Interior.ColorIndex = 0 And _ Range("A29:G49,K29:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 72 Then Range ("A8:G37,K8:Q37").Interior.ColorIndex = 0 And _ Range("A38:G49,K38:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 84 Then Range ("A8:G43,K8:Q43").Interior.ColorIndex = 0 And _ Range("A44:G49,K44:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 96 Then Range ("A8:G49,K8:Q49").Interior.ColorIndex = 0 End Sub |
ComboBox programming not working
Try this:
Private Sub ComboBox1_Change() Select Case CLng(Combobox1.Value) Case 12 Range("A8:G49,K8:Q49").Interior.ColorIndex = 15 Case 18 Range("A8:G10,K8:Q10").Interior.ColorIndex = 0 Range("A11:G49,K11:Q49").Interior.ColorIndex = 15 Case 20 Range("A8:G11,K8:Q11").Interior.ColorIndex = 0 Range("A12:G49,K12:Q49").Interior.ColorIndex = 15 Case 24 Range("A8:G13,K8:Q13").Interior.ColorIndex = 0 Range("A14:G49,K14:Q49").Interior.ColorIndex = 15 Case 30 Range("A8:G16,K8:Q16").Interior.ColorIndex = 0 Range("A17:G49,K17:Q49").Interior.ColorIndex = 15 Case 42 Range("A8:G22,K8:Q22").Interior.ColorIndex = 0 Range("A23:G49,K23:Q49").Interior.ColorIndex = 15 Case 54 Range("A8:G28,K8:Q28").Interior.ColorIndex = 0 Range("A29:G49,K29:Q49").Interior.ColorIndex = 15 Case 72 Range("A8:G37,K8:Q37").Interior.ColorIndex = 0 Range("A38:G49,K38:Q49").Interior.ColorIndex = 15 Case 84 Range("A8:G43,K8:Q43").Interior.ColorIndex = 0 Range("A44:G49,K44:Q49").Interior.ColorIndex = 15 Case 96 Range("A8:G49,K8:Q49").Interior.ColorIndex = 0 End Select End Sub -- Regards, Tom Ogilvy "DontKnowWhatImDoing" wrote in message ... If anyone can help?! Problem I have is that my combobox has values and if you select the lowest value (12) first then any larger value it works fine, but if you select a larger value fisrt then a lower value second, nothing happens. Here is the code I have. Private Sub ComboBox1_Change() If ComboBox1.Value = 12 Then Range ("A8:G49,K8:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 18 Then Range ("A8:G10,K8:Q10").Interior.ColorIndex = 0 And _ Range("A11:G49,K11:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 20 Then Range ("A8:G11,K8:Q11").Interior.ColorIndex = 0 And _ Range("A12:G49,K12:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 24 Then Range ("A8:G13,K8:Q13").Interior.ColorIndex = 0 And _ Range("A14:G49,K14:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 30 Then Range ("A8:G16,K8:Q16").Interior.ColorIndex = 0 And _ Range("A17:G49,K17:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 42 Then Range ("A8:G22,K8:Q22").Interior.ColorIndex = 0 And _ Range("A23:G49,K23:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 54 Then Range ("A8:G28,K8:Q28").Interior.ColorIndex = 0 And _ Range("A29:G49,K29:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 72 Then Range ("A8:G37,K8:Q37").Interior.ColorIndex = 0 And _ Range("A38:G49,K38:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 84 Then Range ("A8:G43,K8:Q43").Interior.ColorIndex = 0 And _ Range("A44:G49,K44:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 96 Then Range ("A8:G49,K8:Q49").Interior.ColorIndex = 0 End Sub |
ComboBox programming not working
Try this instead
Private Sub ComboBox1_Change() Select Case ComboBox1.Value case12 Range("A8:G49,K8:Q49").Interior.ColorIndex = 15 Case 18 Range("A8:G10,K8:Q10").Interior.ColorIndex = 0 Range("A11:G49,K11:Q49").Interior.ColorIndex = 15 Case 20 Range("A8:G11,K8:Q11").Interior.ColorIndex = 0 Range("A12:G49,K12:Q49").Interior.ColorIndex = 15 Case 24 Range("A8:G13,K8:Q13").Interior.ColorIndex = 0 Range("A14:G49,K14:Q49").Interior.ColorIndex = 15 Case 30 Range("A8:G16,K8:Q16").Interior.ColorIndex = 0 Range("A17:G49,K17:Q49").Interior.ColorIndex = 15 Case 42 Range("A8:G22,K8:Q22").Interior.ColorIndex = 0 Range("A23:G49,K23:Q49").Interior.ColorIndex = 15 Case 54 Range("A8:G28,K8:Q28").Interior.ColorIndex = 0 Range("A29:G49,K29:Q49").Interior.ColorIndex = 15 Case 72 Range("A8:G37,K8:Q37").Interior.ColorIndex = 0 Range("A38:G49,K38:Q49").Interior.ColorIndex = 15 Case 84 Range("A8:G43,K8:Q43").Interior.ColorIndex = 0 Range("A44:G49,K44:Q49").Interior.ColorIndex = 15 Case 96 Range("A8:G49,K8:Q49").Interior.ColorIndex = 0 End Select End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "DontKnowWhatImDoing" wrote in message ... If anyone can help?! Problem I have is that my combobox has values and if you select the lowest value (12) first then any larger value it works fine, but if you select a larger value fisrt then a lower value second, nothing happens. Here is the code I have. Private Sub ComboBox1_Change() If ComboBox1.Value = 12 Then Range ("A8:G49,K8:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 18 Then Range ("A8:G10,K8:Q10").Interior.ColorIndex = 0 And _ Range("A11:G49,K11:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 20 Then Range ("A8:G11,K8:Q11").Interior.ColorIndex = 0 And _ Range("A12:G49,K12:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 24 Then Range ("A8:G13,K8:Q13").Interior.ColorIndex = 0 And _ Range("A14:G49,K14:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 30 Then Range ("A8:G16,K8:Q16").Interior.ColorIndex = 0 And _ Range("A17:G49,K17:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 42 Then Range ("A8:G22,K8:Q22").Interior.ColorIndex = 0 And _ Range("A23:G49,K23:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 54 Then Range ("A8:G28,K8:Q28").Interior.ColorIndex = 0 And _ Range("A29:G49,K29:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 72 Then Range ("A8:G37,K8:Q37").Interior.ColorIndex = 0 And _ Range("A38:G49,K38:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 84 Then Range ("A8:G43,K8:Q43").Interior.ColorIndex = 0 And _ Range("A44:G49,K44:Q49").Interior.ColorIndex = 15 Else If ComboBox1.Value = 96 Then Range ("A8:G49,K8:Q49").Interior.ColorIndex = 0 End Sub |
All times are GMT +1. The time now is 01:52 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com