Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default UDF Function or Macro Needed

Hi,

I've tried all kinds of things, but this problem is beyond me...
Ideally I need a UDF function or a small macro to be created.

The facts a....

- Every cell in a particular column(s) has multiple characters
(string) at the begining with a numbers(s) at the end.
- The characters could possibly have spaces.
- The numbers might have a negative sign proceeding the number itself
or a decimal or both.

Problem is:

I need this column to be split into two columns with one containing
the characters and the other containing the number.

Example:

CELL A1 Contains: ABSHHF KJGG -1524.001

The function would put ABSHHF KJGG into cell A2 and -1524.001 into
cell A3.

That's it.

Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default UDF Function or Macro Needed

- The numbers might have a negative sign proceeding the number itself
or a decimal or both.


Is "or none of them" a possible case?

Stefi


€˛qcan€¯ ezt Ć*rta:

Hi,

I've tried all kinds of things, but this problem is beyond me...
Ideally I need a UDF function or a small macro to be created.

The facts a....

- Every cell in a particular column(s) has multiple characters
(string) at the begining with a numbers(s) at the end.
- The characters could possibly have spaces.
- The numbers might have a negative sign proceeding the number itself
or a decimal or both.

Problem is:

I need this column to be split into two columns with one containing
the characters and the other containing the number.

Example:

CELL A1 Contains: ABSHHF KJGG -1524.001

The function would put ABSHHF KJGG into cell A2 and -1524.001 into
cell A3.

That's it.

Thanks,

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default UDF Function or Macro Needed

Select cells in a single column and run the macro.

Two assumptions:
- there's always text to left and a number to right
- there's always a space between the text and number

Sub TxtLt_NumRt()
Dim pos As Long
Dim s As String
Dim cell As Range

For Each cell In Selection
s = cell
pos = InStrRev(s, " ")
If pos Then
cell.Offset(0, 1) = Left$(s, pos - 1)
cell.Offset(0, 2) = Right$(s, Len(s) - pos)
End If
Next

End Sub

Revert if cannot rely on the assumptions.

Something similar could be done with a UDF but only if array entered in
pairs of cells.

Regards,
Peter T

"qcan" wrote in message
...
Hi,

I've tried all kinds of things, but this problem is beyond me...
Ideally I need a UDF function or a small macro to be created.

The facts a....

- Every cell in a particular column(s) has multiple characters
(string) at the begining with a numbers(s) at the end.
- The characters could possibly have spaces.
- The numbers might have a negative sign proceeding the number itself
or a decimal or both.

Problem is:

I need this column to be split into two columns with one containing
the characters and the other containing the number.

Example:

CELL A1 Contains: ABSHHF KJGG -1524.001

The function would put ABSHHF KJGG into cell A2 and -1524.001 into
cell A3.

That's it.

Thanks,



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default UDF Function or Macro Needed

I mean e.g. ABSHHF KJGG 1524.001 is a possible case?
Stefi


€˛qcan€¯ ezt Ć*rta:

Hi,

I've tried all kinds of things, but this problem is beyond me...
Ideally I need a UDF function or a small macro to be created.

The facts a....

- Every cell in a particular column(s) has multiple characters
(string) at the begining with a numbers(s) at the end.
- The characters could possibly have spaces.
- The numbers might have a negative sign proceeding the number itself
or a decimal or both.

Problem is:

I need this column to be split into two columns with one containing
the characters and the other containing the number.

Example:

CELL A1 Contains: ABSHHF KJGG -1524.001

The function would put ABSHHF KJGG into cell A2 and -1524.001 into
cell A3.

That's it.

Thanks,

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default UDF Function or Macro Needed

Hi
Some cell formulas. If your string is in A1 then in B1 put

=IF(ISERROR(FIND("-",A1)),CLEAN(LEFT(A1,FIND(".",A1)-1)),CLEAN(LEFT(A1,FIND("-",A1)-1)))

and in C1 put

=IF(ISERROR(FIND("-",A1)),CLEAN(RIGHT(A1,LEN(A1)-
FIND(".",A1)+1)),CLEAN(RIGHT(A1,LEN(A1)-FIND("-",A1)+1)))

You can then fill these down.
The first formula looks to see if it can find a "-". If it can't it
finds the position of the first "." and returns the string to the left
of the dot without any trailing space. If it can it returns the same
string to the left of the first "-".
The second formula does the same except from the right.

regards
Paul

On Feb 7, 4:52*am, qcan wrote:
Hi,

I've tried all kinds of things, but this problem is beyond me...
Ideally I need a UDF function or a small macro to be created.

The facts a....

- Every cell in a particular column(s) has multiple characters
(string) at the begining with a numbers(s) at the end.
- The characters could possibly have spaces.
- The numbers might have a negative sign proceeding the number itself
or a decimal or both.

Problem is:

I need this column to be split into two columns with one containing
the characters and the other containing the number.

Example:

CELL A1 Contains: ABSHHF KJGG -1524.001

The function would put ABSHHF KJGG into cell A2 and -1524.001 into
cell A3.

That's it.

Thanks,




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default UDF Function or Macro Needed

On Wed, 6 Feb 2008 20:52:59 -0800 (PST), qcan wrote:

Hi,

I've tried all kinds of things, but this problem is beyond me...
Ideally I need a UDF function or a small macro to be created.

The facts a....

- Every cell in a particular column(s) has multiple characters
(string) at the begining with a numbers(s) at the end.
- The characters could possibly have spaces.
- The numbers might have a negative sign proceeding the number itself
or a decimal or both.

Problem is:

I need this column to be split into two columns with one containing
the characters and the other containing the number.

Example:

CELL A1 Contains: ABSHHF KJGG -1524.001

The function would put ABSHHF KJGG into cell A2 and -1524.001 into
cell A3.

That's it.

Thanks,


Here are two UDF's that will extract the string portion or the numeric portion
of the entry.

It returns a #NUM! error if the string does not contain a number at the end.

If the format is different than what you describe, it may need some minor
tweaking. For example, if the last character(s) is not a digit.

==============================
Option Explicit
Function NumAtEnd(str As String)
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "[\-+]?\d*\.?\d+$"
If re.test(str) = True Then
Set mc = re.Execute(str)
NumAtEnd = CDbl(mc(0))
Else
NumAtEnd = CVErr(xlErrNum)
End If
End Function
'------------------------------------
Function GetString(str As String)
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.Pattern = "[\-+]?\d*\.?\d+$"
GetString = Trim(re.Replace(str, ""))
End Function
=====================================
--ron
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default UDF Function or Macro Needed

On Feb 6, 11:52*pm, qcan wrote:
Hi,

I've tried all kinds of things, but this problem is beyond me...
Ideally I need a UDF function or a small macro to be created.

The facts a....

- Every cell in a particular column(s) has multiple characters
(string) at the begining with a numbers(s) at the end.
- The characters could possibly have spaces.
- The numbers might have a negative sign proceeding the number itself
or a decimal or both.

Problem is:

I need this column to be split into two columns with one containing
the characters and the other containing the number.

Example:

CELL A1 Contains: ABSHHF KJGG -1524.001

The function would put ABSHHF KJGG into cell A2 and -1524.001 into
cell A3.

That's it.

Thanks,


Thank you everybody for your effort & time. Special thanks to Peter T.
You NAILED it the 1st time. It's FLAWLESS.
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
Needed Macro and Function Help GEdwards Excel Discussion (Misc queries) 1 April 21st 10 06:06 PM
Detailed Function (or Macro) Needed... Help akemeny Excel Worksheet Functions 3 September 16th 08 07:32 PM
macro or function help needed for adding columns for values missin Arain Excel Discussion (Misc queries) 10 May 17th 07 12:46 AM
HELP NEEDED FOR IF Function Inside a Macro Sandi Excel Worksheet Functions 1 June 2nd 06 04:14 AM
A count function or macro needed dkenebre Excel Programming 2 November 15th 03 06:00 PM


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