Solved

Count non-numeric values in a worksheet range

Posted on 2014-10-12
7
223 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)
[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 51

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 (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
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.

 
LVL 51

Accepted Solution

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

maybe

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

Regards
0
 
LVL 48

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 51

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 (Access MVP)
ID: 40376855
This seems to have done the trick.  Thanks.
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

705 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