Solved

Count non-numeric values in a worksheet range

Posted on 2014-10-12
7
212 Views
Last Modified: 2014-10-13
I'm exporting some data from Access to Excel.  In Access the data type of several of the columns is Text, but these columns only contain numeric values (no leading zeros).

When I export this data to Excel, it treats the data as text as well, but I would like convert it to a number.  I've found that the Excel Range.TextToColumns method works to convert these values to numbers, so after exporting, I go to the various columns and use that method to convert the data.

Now I'm working on a more generic routine, and I don't want to hard code the column names, I simply want to test the data type of the field.  If it is text, I want to count to see if any of the "values" in that range are non-numeric.  If they are, then I won't do the conversion, but if all of the cells in a range are numeric, then I'll do the conversion.

So, is there a method or function in Excel which will allow me to get a count of the non-numeric cells in a range?
0
Comment
Question by:Dale Fye (Access MVP)
  • 3
  • 3
7 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,

pls try

Result = Evaluate("COUNTA(A1:A100)-COUNT(A1:A100*1)")


Regards
0
 
LVL 47

Author Comment

by:Dale Fye (Access MVP)
Comment Utility
Rgonzo,

I already have a rng object, and when I do:

Evaluate("CountA(rng)") it returns 1, even if the range has hundreds of rows with values.

and

Evaluate("Count(rng*1)") is returning zero (0) because it is apparently not recognizing these text values as numbers.

I've already got a little function that loops through the cells of the range and counts them, then uses IsNumeric to determine whether the cell is numeric, but was just wondering whether this could be done with a single line.

Dale
0
 
LVL 31

Expert Comment

by:Rob Henson
Comment Utility
In Access the data type of several of the columns is Text, but these columns only contain numeric values (no leading zeros).

You have only numeric values. Would it not make sense to therefore change the data type in Access?

Thanks
Rob H
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 48

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
Hi,

maybe

Res = Evaluate("COUNTA(" & Rng.Address & ")-COUNT(" & Rng.Address & " * 1)")

Regards
0
 
LVL 47

Author Comment

by:Dale Fye (Access MVP)
Comment Utility
Rob,

It would yes, but for compatibility between Access and other databases where the data originally came from, I have left it as text (makes it much less complicated to perform joins on those fields).

Rgonzo,

What is the purpose of the "*1" in your function?
0
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
*1
transforms the a numeric value as text to a number in an array formula

Regards
0
 
LVL 47

Author Closing Comment

by:Dale Fye (Access MVP)
Comment Utility
This seems to have done the trick.  Thanks.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
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.

772 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