A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

pulling out Numbers



 
 
Thread Tools Display Modes
  #21  
Old August 22nd, 2007, 01:49 AM posted to microsoft.public.excel.misc
Ron Rosenfeld
external usenet poster
 
Posts: 3,719
Default pulling out Numbers

On Tue, 21 Aug 2007 16:56:02 -0700, peyman
wrote:

thanx Ron.It's excellent


You should look at some of the references I gave Mike to learn about
constructing regular expressions. There are also many other ways to use them.
--ron
  #22  
Old August 22nd, 2007, 05:12 PM posted to microsoft.public.excel.misc
peyman
external usenet poster
 
Posts: 193
Default pulling out Numbers

hi Ron,
where should I locate the following commands in the UDF codes?
=resub(A1,"\d","") or =resub(A1,"\D",""), =resub....
and what does A1 or A6 stand for?
thanx

"Ron Rosenfeld" wrote:

On Tue, 21 Aug 2007 15:12:01 -0700, peyman
wrote:

hi Ron,
Can we do it reverse.pulling out only letters.
aa125df36 to aadf????
thank you


It's pretty simple. In the code I posted, you just need to change the "\D",
which selects all non-digits for removal, to a "\d" which selects all digits
for removal.

But for more flexibility, you could include the arguments for what to find, and
what to replace it with, in the function code.

For example, with this UDF:

=====================================
Option Explicit
Function ReSub(str As String, FindText As String, ReplaceWith As String)
Dim re As Object
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.Pattern = FindText
ReSub = re.Replace(str, ReplaceWith)
End Function
======================================

You could use this formula to replace all digits with a null string, resulting
in pulling out only letters:

=resub(A1,"\d","")

If you wanted to pull out only digits, then:

=resub(A1,"\D","")

If you wanted to replace the digits with a tilde, you could use:

=resub(A1,"\d","~")

If you wanted to replace all of the letters with the word Peyman, with leading
and ending spaces, then:

=resub(A6,"\D"," Peyman ")

And many other solutions

--ron

  #23  
Old August 22nd, 2007, 05:53 PM posted to microsoft.public.excel.misc
Ron Rosenfeld
external usenet poster
 
Posts: 3,719
Default pulling out Numbers

On Wed, 22 Aug 2007 09:12:00 -0700, peyman
wrote:

hi Ron,
where should I locate the following commands in the UDF codes?
=resub(A1,"\d","") or =resub(A1,"\D",""), =resub....


I don't know what you mean by that question.

=resub(A1,"\d","") is a function you enter in a worksheet cell.

and what does A1 or A6 stand for?


A1 "stands for" the worksheet cell that is in the first row and first column of
your sheet (upper left corner).

A6 "stands for" the worksheet cell located in the 6th row of the first column.

In my first post, I used cell_ref for that. But I thought that by now you
would realize that these are just arbitrary cell references to where I happened
to have the test string.

If you are using the R1C1 reference system, then A1 is the same as R1C1, and A6
is the same R6C1.
--ron
  #24  
Old August 22nd, 2007, 06:06 PM posted to microsoft.public.excel.misc
peyman
external usenet poster
 
Posts: 193
Default pulling out Numbers

Sorry Ron, I got it.thanx

"Ron Rosenfeld" wrote:

On Wed, 22 Aug 2007 09:12:00 -0700, peyman
wrote:

hi Ron,
where should I locate the following commands in the UDF codes?
=resub(A1,"\d","") or =resub(A1,"\D",""), =resub....


I don't know what you mean by that question.

=resub(A1,"\d","") is a function you enter in a worksheet cell.

and what does A1 or A6 stand for?


A1 "stands for" the worksheet cell that is in the first row and first column of
your sheet (upper left corner).

A6 "stands for" the worksheet cell located in the 6th row of the first column.

In my first post, I used cell_ref for that. But I thought that by now you
would realize that these are just arbitrary cell references to where I happened
to have the test string.

If you are using the R1C1 reference system, then A1 is the same as R1C1, and A6
is the same R6C1.
--ron

  #25  
Old August 22nd, 2007, 06:27 PM posted to microsoft.public.excel.misc
Ron Rosenfeld
external usenet poster
 
Posts: 3,719
Default pulling out Numbers

On Wed, 22 Aug 2007 10:06:02 -0700, peyman
wrote:

Sorry Ron, I got it.thanx


No need to apologize. Sometimes I assume mind reading abilities where none
exists :-))
--ron
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 03:50 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.