?
Solved

Count non-numeric values in a worksheet range

Posted on 2014-10-12
7
Medium Priority
?
224 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
[X]
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
  • 3
  • 3
7 Comments
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40375860
Hi,

pls try

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


Regards
0
 
LVL 48

Author Comment

by:Dale Fye
ID: 40376746
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 33

Expert Comment

by:Rob Henson
ID: 40376752
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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 40376807
Hi,

maybe

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

Regards
0
 
LVL 48

Author Comment

by:Dale Fye
ID: 40376829
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 52

Expert Comment

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

Regards
0
 
LVL 48

Author Closing Comment

by:Dale Fye
ID: 40376855
This seems to have done the trick.  Thanks.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

762 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