Solved

Count non-numeric values in a worksheet range

Posted on 2014-10-12
7
218 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 50

Expert Comment

by:Rgonzo1971
ID: 40375860
Hi,

pls try

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


Regards
0
 
LVL 47

Author Comment

by:Dale Fye (Access MVP)
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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 50

Accepted Solution

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

maybe

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

Regards
0
 
LVL 47

Author Comment

by:Dale Fye (Access MVP)
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 50

Expert Comment

by:Rgonzo1971
ID: 40376843
*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)
ID: 40376855
This seems to have done the trick.  Thanks.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
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…

856 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