Good afternoon. I have a workbook where the user can make a selection then produce a chart. My 'problem' is how to ensure that there is a valid value in a cell (F13) dependent on the selection in cell F9 before the user clicks a button to produce a chart. For example if F9 = “By Brand” then F13 will show a list of all the brands, e.g. “Ford”, Mazda” etc. If F9 = “By Type” then F13 will show a list of all the types, e.g. “Saloon”, Hatch” etc.
What I want to error-check is, say, when F9 = “By Brand” & F13 = “Ford” but then the user changes F9 to “By Type” but doesn’t re-select the type in F13 before clicking the ‘Chart’ button. There isn’t a “type” called “Ford” so I want to put some checking in the code to ensure that F13 & F9 are compatible.
Each drop-down/list is selected from a named range on Sheet “Ref”, e.g. “TAB_Brands”.
So I tried putting together some code to test whether F13 is in the list as defined by F9:-
Code:
Select Case Sheets("Chart").Range("F9")
Case "By Brand"
MyTest = Sheets("Chart").Range("F13")
MyRange = "TAB_Brands"
If InStr(1, MyTest, MyRange) Then
Always results in 0.
The way round that I’ve found is:-
Code:
MyRangeCount = Sheets("Ref").Range("TAB_Brands").Rows.Count
For x = 1 To MyRangeCount
If InStr(1, MyTest, Sheets("Ref").Range(MyRange).Rows(x)) Then GoTo Line10
Next x
MsgBox "Mis-match in Chart selection"
Exit Sub
.
.
.
.
.
Line10:
Select Case Sheets("Chart").Range("F11")
Case "Monthly"
.
.
.
I also know that “GoTo” is frowned upon in these circles so I’d appreciate a pointer on that. BTW the data isn’t actually about cars so there are actually two possible types under “Brand” – say “UPVC” & “Wood”.
Many thanks,
D€$