Hello Guys,
I would like to receive back the specific "ID" value from check-sheet based on multiple criterias in VBA. I using Userform for data input, where I input all related informations and based on these values should I get the specific project "ID" from the data-base check-sheet.
The "ID" should be defined based on 3 criterias (part number, class type, revision number), but when I'm using Index.Match function then during program running I'm always facing with Type Mismatch error.
Does somebody have any idea, how I can solve and use the given formular or any other idea, how to lookup "ID" with 3 criterias? Thank you!
Private Sub OptionButton_Customer_Click()
If OptionButton_Internal.value = True Then
selected_type = OptionButton_Internal.Caption
ElseIf OptionButton_Customer.value = True Then
selected_type = OptionButton_Customer.Caption
ElseIf OptionButton_Supplier.value = True Then
selected_type = OptionButton_Supplier.Caption
End If
Set rev_data = Sheet7 'Set data-sheet
lr = rev_data.Range("A:A").SpecialCells(xlCellTypeLastCell).Row 'Found the last row in column
Set Rng1 = Sheet7.Range("E2:E" & lr) 'Define range for revision
Set Rng2 = Sheet7.Range("D2:D" & lr) 'Define range for part number
Set Rng3 = Sheet7.Range("F2:F" & lr) 'Define range for class type
Set Rng4 = Sheet7.Range("B2:B" & lr) 'Define range project id
sy = Application.WorksheetFunction.MaxIfs(Rng1, Rng2, L_Part_Number.value, Rng3, selected_type)
search_id = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Index(rev_data.Range("B2:B7"), _
Application.WorksheetFunction.Match(1, (L_Part_Number.value = Rng2) * (OptionButton_Customer.Caption = Rng3) * (sy = Rng1), 0)), "The value is not existing")
MsgBox "ID Number:" & search_id
End Sub
I would like to receive back the specific "ID" value from check-sheet based on multiple criterias in VBA. I using Userform for data input, where I input all related informations and based on these values should I get the specific project "ID" from the data-base check-sheet.
The "ID" should be defined based on 3 criterias (part number, class type, revision number), but when I'm using Index.Match function then during program running I'm always facing with Type Mismatch error.
Does somebody have any idea, how I can solve and use the given formular or any other idea, how to lookup "ID" with 3 criterias? Thank you!
Private Sub OptionButton_Customer_Click()
If OptionButton_Internal.value = True Then
selected_type = OptionButton_Internal.Caption
ElseIf OptionButton_Customer.value = True Then
selected_type = OptionButton_Customer.Caption
ElseIf OptionButton_Supplier.value = True Then
selected_type = OptionButton_Supplier.Caption
End If
Set rev_data = Sheet7 'Set data-sheet
lr = rev_data.Range("A:A").SpecialCells(xlCellTypeLastCell).Row 'Found the last row in column
Set Rng1 = Sheet7.Range("E2:E" & lr) 'Define range for revision
Set Rng2 = Sheet7.Range("D2:D" & lr) 'Define range for part number
Set Rng3 = Sheet7.Range("F2:F" & lr) 'Define range for class type
Set Rng4 = Sheet7.Range("B2:B" & lr) 'Define range project id
sy = Application.WorksheetFunction.MaxIfs(Rng1, Rng2, L_Part_Number.value, Rng3, selected_type)
search_id = Application.WorksheetFunction.IfError(Application.WorksheetFunction.Index(rev_data.Range("B2:B7"), _
Application.WorksheetFunction.Match(1, (L_Part_Number.value = Rng2) * (OptionButton_Customer.Caption = Rng3) * (sy = Rng1), 0)), "The value is not existing")
MsgBox "ID Number:" & search_id
End Sub