Solved

Validate column contents with VBA

Posted on 2013-05-15
4
204 Views
Last Modified: 2013-07-04
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
Comment
Question by:Blowfelt82
  • 2
4 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39167451
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
 

Author Comment

by:Blowfelt82
ID: 39167469
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
 
LVL 32

Accepted Solution

by:
Rob Henson earned 500 total points
ID: 39167643
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
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39300562
(Comment posted on 15 May 2013 accepted on 4 July 2013)
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question