Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

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?
0
Blowfelt82
Asked:
Blowfelt82
  • 2
1 Solution
 
[ fanpages ]IT Services ConsultantCommented:
Hi,

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.
0
 
Blowfelt82Author Commented:
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?
0
 
Rob HensonIT & Database AssistantCommented:
Are you able to setup a table of valid options for each column?

If so you could use the VLOOKUP function to validate an entry against it's relevant column in the above table.

For numerical values you could set the table as minimum and maximum and then check a value is in the range (MIN & MAX functions).

You could have multiple check columns (one for each entry column) and a count of errors in a row. Or you could have a single check column and then have a routine that changes the column for which the formula is checking and making a note of each error.

Thanks
Rob H
0
 
[ fanpages ]IT Services ConsultantCommented:
(Comment posted on 15 May 2013 accepted on 4 July 2013)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now