Solved

Validate column contents with VBA

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

744 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

11 Experts available now in Live!

Get 1:1 Help Now