Blowfelt82
asked on
Validate column contents with VBA
I am looking for a way I can validate the columns in my spread sheet. At the moment all of the data in the spread sheet is loaded from externally sourced files and web queries -so I want a way I can validate the columns contain the data I expect i.e. a number, a value within a known set. All the columns in the spread sheet are identifiable by named groups so I would like to use these to identify the columns.
My first thought is just to iterate through all columns in the named group (excluding header) and test each row - unless there is a more elegant solution?
My first thought is just to iterate through all columns in the named group (excluding header) and test each row - unless there is a more elegant solution?
ASKER
The data is being directly uploaded from a website (which I do not have ownership of) using an excel data query so I don't think there is any possibility of validating prior to getting the results in Excel unfortunately. I have created a custom ribbon button linked to a VBA function where I want the validation to take place - and my intent is for the spread sheet user to use this after the data has been loaded to confirm the data is OK.
Each column will have its own specific rules for validation i.e. a number, a value in a set and I just want the user to be informed that the data does not meet the validation rules. A message box would suffice?
Perhaps a VBA query to get distinct values from a column and then just compare this list with a list of expected values. Then repeat this for each column?
Each column will have its own specific rules for validation i.e. a number, a value in a set and I just want the user to be informed that the data does not meet the validation rules. A message box would suffice?
Perhaps a VBA query to get distinct values from a column and then just compare this list with a list of expected values. Then repeat this for each column?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(Comment posted on 15 May 2013 accepted on 4 July 2013)
What is your intended outcome if one or more values fail the validation test?
Also, what (or whom) is the eventual recipient of the data?
Will that system (or person's) processing fail if invalid data is passed & you wish to avoid that, or will the data be rejected within the ongoing process (& you need to record the failures in advance)?
Additionally, can the data not be validated during the extracting/loading process, &/or rejected at source?
The "named group" validation is a suitable approach though, depending on execution time.
BFN,
fp.