Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default VBA question: editing alpha characters out of numeric values

Hi all;

I've got a LOT of numerical data in Excel workbooks to process and work
with.

The individual sheets contain 12-15 columns and 500-2000 rows or mostly
numerical data. However, many of the individual cell values have
alpha-characters as footnotes, e.g.: cell B12 might have the value "5.0a".
In addition, a lot of the cells have a "less than" comparitor, e.g.:
"<5.0", and "<5.0a"

I can deal with the "<" easily enough by using a global find-replace,
replacing it as a negative sign, and treating the vlaue as a negative
number. I can also do a global find-replace for each letter in the
alphabet, and replce the character with nothing.

But is there an easier way to get rid of the alpha-character footnotes than
using 26 find-replace statements? Is there a function or command or
statement that can get rid of all alpha-characters without having to call
out each one?

Thanks a heap,
-jbb

--
J.B.Bobbitt


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default VBA question: editing alpha characters out of numeric values

JB,

Here's a 5 minute try at it. I haven't got your data, so be careful and
backup your sheet FIRST please.

Sub ReplaceWithNumericValues()
Dim rngCell As Range

'backup your sheet FIRST
'select the range first
For Each rngCell In Selection

rngCell.Value = FindNumericSubString(rngCell)

Next rngCell

End Sub

Function FindNumericSubString(rngCell As Range) As Variant
Dim nCounter As Integer
Dim nChr As Integer
Dim strValue As String
Dim strOutput As String
Dim nLength As Integer

If IsEmpty(rngCell.Value) Then Exit Function

If IsNumeric(rngCell.Value) Then

FindNumericSubString = rngCell.Value
Exit Function

End If

nCounter = 1
strValue = rngCell.Value
nLength = Len(strValue)

nChr = Asc(Mid(strValue, nCounter, 1))

Do Until (nChr = 48 And nChr <= 57) Or nChr = 45 Or nChr = 46

nCounter = nCounter + 1
nChr = Asc(Mid(strValue, nCounter, 1))
If nCounter nLength Then Exit Function

Loop

strOutput = Chr(nChr)
nCounter = nCounter + 1
nChr = Asc(Mid(strValue, nCounter, 1))

Do While ((nChr = 48 And nChr <= 57) Or nChr = 46)

strOutput = strOutput & Mid(strValue, nCounter, 1)
nCounter = nCounter + 1
If nCounter nLength Then Exit Do
nChr = Asc(Mid(strValue, nCounter, 1))

Loop

On Error Resume Next
FindNumericSubString = CDbl(strOutput)
On Error GoTo 0

End Function

Robin Hammond
www.enhanceddatasystems.com


"J.B. Bobbitt" wrote in message
ink.net...
Hi all;

I've got a LOT of numerical data in Excel workbooks to process and work
with.

The individual sheets contain 12-15 columns and 500-2000 rows or mostly
numerical data. However, many of the individual cell values have
alpha-characters as footnotes, e.g.: cell B12 might have the value
"5.0a". In addition, a lot of the cells have a "less than" comparitor,
e.g.: "<5.0", and "<5.0a"

I can deal with the "<" easily enough by using a global find-replace,
replacing it as a negative sign, and treating the vlaue as a negative
number. I can also do a global find-replace for each letter in the
alphabet, and replce the character with nothing.

But is there an easier way to get rid of the alpha-character footnotes
than using 26 find-replace statements? Is there a function or command or
statement that can get rid of all alpha-characters without having to call
out each one?

Thanks a heap,
-jbb

--
J.B.Bobbitt



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default VBA question: editing alpha characters out of numeric values

Wow. Thanks for the effort, Robin.

-jbb

"Robin Hammond" wrote in message
...
JB,

Here's a 5 minute try at it. I haven't got your data, so be careful and
backup your sheet FIRST please.

Sub ReplaceWithNumericValues()
Dim rngCell As Range

'backup your sheet FIRST
'select the range first
For Each rngCell In Selection

rngCell.Value = FindNumericSubString(rngCell)

Next rngCell

End Sub

Function FindNumericSubString(rngCell As Range) As Variant
Dim nCounter As Integer
Dim nChr As Integer
Dim strValue As String
Dim strOutput As String
Dim nLength As Integer

If IsEmpty(rngCell.Value) Then Exit Function

If IsNumeric(rngCell.Value) Then

FindNumericSubString = rngCell.Value
Exit Function

End If

nCounter = 1
strValue = rngCell.Value
nLength = Len(strValue)

nChr = Asc(Mid(strValue, nCounter, 1))

Do Until (nChr = 48 And nChr <= 57) Or nChr = 45 Or nChr = 46

nCounter = nCounter + 1
nChr = Asc(Mid(strValue, nCounter, 1))
If nCounter nLength Then Exit Function

Loop

strOutput = Chr(nChr)
nCounter = nCounter + 1
nChr = Asc(Mid(strValue, nCounter, 1))

Do While ((nChr = 48 And nChr <= 57) Or nChr = 46)

strOutput = strOutput & Mid(strValue, nCounter, 1)
nCounter = nCounter + 1
If nCounter nLength Then Exit Do
nChr = Asc(Mid(strValue, nCounter, 1))

Loop

On Error Resume Next
FindNumericSubString = CDbl(strOutput)
On Error GoTo 0

End Function

Robin Hammond
www.enhanceddatasystems.com


"J.B. Bobbitt" wrote in message
ink.net...
Hi all;

I've got a LOT of numerical data in Excel workbooks to process and work
with.

The individual sheets contain 12-15 columns and 500-2000 rows or mostly
numerical data. However, many of the individual cell values have
alpha-characters as footnotes, e.g.: cell B12 might have the value
"5.0a". In addition, a lot of the cells have a "less than" comparitor,
e.g.: "<5.0", and "<5.0a"

I can deal with the "<" easily enough by using a global find-replace,
replacing it as a negative sign, and treating the vlaue as a negative
number. I can also do a global find-replace for each letter in the
alphabet, and replce the character with nothing.

But is there an easier way to get rid of the alpha-character footnotes
than using 26 find-replace statements? Is there a function or command or
statement that can get rid of all alpha-characters without having to call
out each one?

Thanks a heap,
-jbb

--
J.B.Bobbitt





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove alpha or non-numeric characters from cell mmanis Excel Discussion (Misc queries) 8 August 7th 09 02:39 AM
A validation rule on Alpha and Numeric characters Sar* Excel Worksheet Functions 11 June 11th 07 11:47 PM
Formulas that include alpha and numeric characters Doktor1 at Mile High Excel Worksheet Functions 2 December 23rd 06 07:36 PM
Can you ID a cell that has both Alpha AND Numeric characters? Phil Excel Worksheet Functions 5 April 18th 06 09:32 PM
code that can distinguish between alpha and numeric characters Boffita Excel Programming 1 September 17th 04 01:23 AM


All times are GMT +1. The time now is 07:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"