I'm relatively new to programming in excel/vba, but I've been tasked with making a simple button in excel. The purpose of this is to use user inputs in one range and then return a value in another range after checking certain conditions. Below you can find my code. So I first associated variables with specific cells. Then in the button_click bit it is to check against the cases/nested if...then statements. The issue is it returns a Type 13 mismatch at the "Case 'H232' Or 'H250'" line and I'm not sure how to fix it. Thanks in advance!
EDIT: To give more detail on the project. Users are to enter the Hazard Codes (H-Codes) used by the GLobal Harmonized System (GHS) for hazard labeling of different products. Users are to enter the appropriate codes in the range H_Code_Input (which I now understand is incorrect). The code is then intended to check user inputs against the conditions outlined in my Select Case, and then produce data in the cells assigned. The numbered output signals either flagged conditions or levels of severity. I will try to set it up as a For Loop running through the column in place of using the H_Code_Input string.
Also I apologize for taking a few days to edit the question. I was out of town this past weekend.
Private Sub GetCellValue()
'Preparing variable values for GHS by assigning them to output cells
Dim Pyrophoric As Range
Set Pyrophoric = Range("G5")
Dim Gas_Under_Pressure As Range
Set Gas_Under_Pressure = Range("G6")
Dim Flammable_Gas As Range
Set Flammable_Gas = Range("G7")
Dim Liquefied_Gas As Range
Set Liquefied_Gas = Range("G8")
Dim Flammable_Liquid As Range
Set Flammable_Liquid = Range("G9")
Dim Oxidizing_Gas As Range
Set Oxidizing_Gas = Range("G10")
Dim Skin_Corrosion As Range
Set Skin_Corrosion = Range("G11")
Dim Eye_Irritant As Range
Set Eye_Irritant = Range("G12")
Dim Respiratory_Sensitizer As Range
Set Respiratory_Sensitizer = Range("G13")
Dim Skin_Sensitizer As Range
Set Skin_Sensitizer = Range("G14")
Dim Germ_Cell_Mutagen As Range
Set Germ_Cell_Mutagen = Range("G15")
Dim Carcinogen As Range
Set Carcinogen = Range("G16")
Dim Respiratory_Hazard As Range
Set Respiratory_Hazard = Range("G17")
Dim STORE As Range
Set STORE = Range("G18")
Dim STOSE As Range
Set STOSE = Range("G19")
Dim Environ_Acute As Range
Set Environ_Acute = Range("G20")
Dim Environ_Chronic As Range
Set Environ_Chronic = Range("G21")
Dim Ozone_Deplete As Range
Set Ozone_Deplete = Range("G22")
'Creating input range
Dim H_Code_Input As Range
Set H_Code_Input = Range("B5:B24")
End Sub
Private Sub CommandButton2_Click()
'Establishing outputs based on user input H codes
Select Case H_Code_Input
Case H_Code_Input = "H232" Or "H250"
Pyrophoric = 1
Case "H280"
Gas_Under_Pressure = 1
Case "H224" Or "H225" Or "H226" Or "H227"
If H_Code_Input.Value = "H224" Then
Flammable_Gas = 1
ElseIf H_Code_Input.Value = "H225" Then
Flammable_Gas = 2
ElseIf H_Code_Input.Value = "H226" Then
Flammable_Gas = 3
ElseIf H_Code_Input.Value = "H227" Then
Flammable_Gas = 4
End If
Case "H270"
Oxidizing_Gas = 1
Case "H314" Or "H315" Or "H316"
If H_Code_Input.Value = "H314" Then
Skin_Corrosion = "1A, B, C"
ElseIf H_Code_Input.Value = "H315" Then
Skin_Corrosion = 2
ElseIf H_Code_Input.Value = "H314" Then
Skin_Corrosion = 3
End If
Case "H318" Or "H319" Or "H320"
If H_Code_Input.Value = "H318" Then
Eye_Irritant = 1
ElseIf H_Code_Input.Value = "H319" Then
Eye_Irritant = "2A"
ElseIf H_Code_Input.Value = "H320" Then
Eye_Irritant = "2B"
End If
Case "H334"
Respiratory_Sensitizer = "1, 1A, 1B"
Case "H317"
Skin_Sensitizer = 1
Case "H340" Or "H341"
If H_Code_Input.Value = "H340" Then
Germ_Cell_Mutagen = "1A, 1B"
ElseIf H_Code_Input.Value = "H341" Then
Germ_Cell_Mutagen = 2
End If
Case "H350" Or "H351-i" Or "H351"
If H_Code_Input.Value = "H350" Or "H350-i" Then
Carcinogen = "1A, 1B"
ElseIf H_Code_Input.Value = "H351" Then
Carcinogen = 2
End If
'Need Respiratory Hazard parameters
Case "H372" Or "H373"
If H_Code_Input.Value = "H372" Then
STORE = 1
ElseIf H_Code_Input.Value = "H373" Then
STORE = 2
End If
Case "H335" Or "H370" Or "H371"
If H_Code_Input.Value = "H335" Then
STOSE = 3
ElseIf H_Code_Input.Value = "H370" Then
STOSE = 1
ElseIf H_Code_Input.Value = "H371" Then
STOSE = 2
End If
Case "H400" Or "H401" Or "H402"
If H_Code_Input.Value = "H400" Then
Environ_Acute = 1
ElseIf H_Code_Input.Value = "H401" Then
Environ_Acute = 2
ElseIf H_Code_Input.Value = "H402" Then
Environ_Acute = 3
End If
Case "H410" Or "H411" Or "H412" Or "H413"
If H_Code_Input.Value = "H410" Then
Environ_Chronic = 1
ElseIf H_Code_Input.Value = "H411" Then
Environ_Chronic = 2
ElseIf H_Code_Input.Value = "H412" Then
Environ_Chronic = 3
ElseIf H_Code_Input.Value = "H413" Then
Environ_Chronic = 4
End If
Case "H420"
Ozone_Deplete = 1
End Select
End Sub
Case "H232" Or "H250"
but I don't think your code can work becauseH_Code_Input
is a multi-cell range. – SJROption Explicit
to the top of the module. And read this for more detail on scope. – BigBen