I'm trying to write code that does the following in VBA but i get error: Type mismatch
Quark is a string variable
If quark = "F" Or "DE" Or "ED" Then
To do this, click on 'Tools' and then click on 'Options'. In the options dialog box, make sure that the 'Auto Syntax Check' option is enabled. If the 'Auto Syntax Check' option is disabled, VBA will still highlight the line with the syntax error in red, but it will not show the error dialog box.
Excel VBA String Comparison. We have a built-in function to compare two strings in VBA: “StrComp.” We can read it as “String Comparison.” This function is available only with VBA and not as a Worksheet function. It compares any two strings and returns the results as “Zero (0)” if both strings match.
You can use the OR operator with the VBA IF statement to test multiple conditions. When you use it, it allows you to test two or more conditions simultaneously and returns true if any of those conditions are true. But if all the conditions are false only then it returns false in the result.
AutoCAD to Excel - VBA Programming Hands-On! There are three types of errors in programming: (a) Syntax Errors, (b) Runtime Errors, and (c) Logical Errors.
Each "OR" is its own boolean statement.
If quark = "F" Or quark ="DE" Or quark ="ED" Then
You could acheive what you are trying to do with a case though I think
Select Case quark
Case "F","DE","ED"
stuffHere
end select
EDIT: I see that you were getting a type mismatch, did you dim quark as a string?
dim quark as string
You may try like to compare like this:-
If quark = "F" Or quark = "DE" Or quark = "ED" Then
instead of:-
If quark = "F" Or "DE" Or "ED" Then
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With