Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
- 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Needed Macro and Function Help | Excel Discussion (Misc queries) | |||
Detailed Function (or Macro) Needed... Help | Excel Worksheet Functions | |||
macro or function help needed for adding columns for values missin | Excel Discussion (Misc queries) | |||
HELP NEEDED FOR IF Function Inside a Macro | Excel Worksheet Functions | |||
A count function or macro needed | Excel Programming |