Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default VB Script to Remove Letters from a number

Hello,

I need to create a script that will allow me to remove two letters at the
end of a number. Most of the time, the number appears as 1234567.00, but
sometimes it comes as 1234567.00CR. I need to remove the two letters at the
end (the letters can change) and leave the decimal and the numbers.

Thanks for your Help

Dave
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default VB Script to Remove Letters from a number

Here is a function that takes a cell and returns the value less the last two
characters if they are not numeric.

Public Function RemoveLetters(ByVal Cell As Range) As Double

If Not IsNumeric(Right(Cell.Value, 2)) Then
RemoveLetters = CDbl(Left(Cell.Value, Len(Cell) - 2))
Else
RemoveLetters = Cell.Value
End If

End Function

This function assumes that your data is not padded with blank characters at
the end.
--
HTH...

Jim Thomlinson


"Dave M" wrote:

Hello,

I need to create a script that will allow me to remove two letters at the
end of a number. Most of the time, the number appears as 1234567.00, but
sometimes it comes as 1234567.00CR. I need to remove the two letters at the
end (the letters can change) and leave the decimal and the numbers.

Thanks for your Help

Dave

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default VB Script to Remove Letters from a number

On Mon, 13 Aug 2007 11:16:01 -0700, Dave M
wrote:

Hello,

I need to create a script that will allow me to remove two letters at the
end of a number. Most of the time, the number appears as 1234567.00, but
sometimes it comes as 1234567.00CR. I need to remove the two letters at the
end (the letters can change) and leave the decimal and the numbers.

Thanks for your Help

Dave



Option Explicit
Sub StripNums()
Dim oRegex As Object
Const sPattern As String = "[A-Za-z]{2}$"

Const s1 = "12345.00"
Const s2 = "12345.00CR"

Set oRegex = CreateObject("VBScript.Regexp")
oRegex.Pattern = sPattern

Debug.Print "s1", oRegex.Replace(s1, "")
Debug.Print "s2", oRegex.Replace(s2, "")
End Sub


--ron
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 1st 2 letters in each row Cathy Excel Discussion (Misc queries) 1 December 15th 09 02:01 PM
Remove dashes between letters and between letters and digits [email protected] Excel Worksheet Functions 7 March 5th 08 06:08 PM
How to remove a Java Script Mac Lingo[_2_] Excel Programming 0 June 10th 05 07:21 PM
VB Script to remove row Dennis Excel Programming 3 November 11th 04 11:24 PM
VB Script to remove row Dennis Excel Programming 1 November 11th 04 11:07 PM


All times are GMT +1. The time now is 06:58 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"