Fishboy
Well-known Member
- Joined
- Feb 13, 2015
- Messages
- 4,267
Hi all,
OK, so I have come a long way since I joined back in February. I started out asking about how different formulas worked to achieve my goals but have since started down the VBA road and am even helping others out along the way.
Progress.
Something I have been trying to do with my own code for some time now, but can't quite get my head around either the syntax or even what it is called to successfully look it up, is how to use an array of values in a VBA If statement. I apologise if I am describing this badly, it might be easier to try and demonstrate what i mean.
So lets say that I want to check if a cell contains one of a number of possible values...
But then I want to check it against a list of possible options. I have seen these in other people's code before where these values are listed in curly braces like this:
{"Red","Yellow","Green","Blue"}
What is the correct syntax or layout for this? Is it:
At present if I wanted to carry out a check like this I would have to resort to lots of OR's...
As mentioned above, not only cannot I not seem to get the syntax right, I don't even know how to word this properly for a decent google search.
If any of the gurus are able to steer me in the right direction it would be greatly appreciated.
OK, so I have come a long way since I joined back in February. I started out asking about how different formulas worked to achieve my goals but have since started down the VBA road and am even helping others out along the way.
Progress.
Something I have been trying to do with my own code for some time now, but can't quite get my head around either the syntax or even what it is called to successfully look it up, is how to use an array of values in a VBA If statement. I apologise if I am describing this badly, it might be easier to try and demonstrate what i mean.
So lets say that I want to check if a cell contains one of a number of possible values...
Rich (BB code):
If ActiveCell.Value =
But then I want to check it against a list of possible options. I have seen these in other people's code before where these values are listed in curly braces like this:
{"Red","Yellow","Green","Blue"}
What is the correct syntax or layout for this? Is it:
Rich (BB code):
If ActiveCell.Value = {"Red","Yellow","Green","Blue"} Then...
The rest of my code
At present if I wanted to carry out a check like this I would have to resort to lots of OR's...
Rich (BB code):
If ActiveCell.Value = "Red" Or ActiveCell.Value = "Yellow" Or ActiveCell.Value = "Green" Or ActiveCell.Value = "Blue" Then...
The rest of my code
As mentioned above, not only cannot I not seem to get the syntax right, I don't even know how to word this properly for a decent google search.
If any of the gurus are able to steer me in the right direction it would be greatly appreciated.