Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Validate column contents with VBA

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

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

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,…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

829 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