Solved

Validate column contents with VBA

Posted on 2013-05-15
4
195 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel file not created as expected 7 48
Tags from access to excel 3 28
Formula 6 46
Auto Adjust Percent rate 5 26
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now