View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
JeffP-> JeffP-> is offline
external usenet poster
 
Posts: 10
Default Help with MID Function?

Here's a VBA example, not as neat as a worksheet function but here ya go...

Cells A1:I1
TTTT100TT
cell J1 enter =GetNumAndChar(A1:I1)

Dragging the lower right corner of this cell to other locations create the
referrenced incremented ranges.

HTH

<begin copy omit this line
Option Explicit

Public Function GetNumAndChar(ByVal rRange As Excel.Range) As String

Dim in_value As String
Dim iRow, iCol, iposit, iStop As Integer
in_value = ""
iRow = 1

For iCol = 1 To rRange.Cells.Count
If rRange.Cells(iRow, iCol) = "." Then iCol = iCol + 1
If IsNumeric(rRange.Cells(iRow, iCol)) Then
in_value = in_value & rRange.Cells(iRow, iCol)
If IsNumeric(rRange.Cells(iRow, iCol)) And Not
IsNumeric(rRange.Cells(iRow, iCol + 1)) Then
in_value = in_value & rRange.Cells(iRow, iCol + 1)
Exit For
End If
End If
Next

If IsNull(in_value) Then
GetNumAndChar = " "
Else: GetNumAndChar = in_value
End If

End Function
<end copy omit this line

"KLZA" wrote:

Hi. I may not have explained myself well enough in my last post. So
here goes again.
I'm trying to capture / extract specific data within a string of text
in a cell. I need to capture a string of numeric characters plus only
the first alpha character immediately after the numbers. The numbers
of alpha characters varies before the numeric characters. So my cells
could look like this: TTTTT10TTTTTT or TTT1000TTTT or
TTTTTTT1TTTTTTTTTTTT etc.. My output from the cells would be 10T or
1000T or 1T etc... The text string before and after the number string
vary. Can this be done?