View Single Post
  #11   Report Post  
Posted to microsoft.public.excel.programming
[email protected] rcmail14872@yahoo.com is offline
external usenet poster
 
Posts: 13
Default parse cell contents

Thank you very much for the great code it works great for what I asked,
but I screwed up when I asked my question. I have been trying to
modify your code without success.

The problem is that I forgot to mention that the valid cell contents
may contain either:
-- a date by itself or
-- one or more footnote references or
-- *both* a date and footnote reference(s).

If there is a date, it must be formatted like: yyyy-mm-dd and it must
be the first thing.
If there are footnote references they must be formatted like:
F1 or
f1 or (upper or lower case "f")
F1,F2 (multiples may go into double digits, up to 99 separate footnote
references is valid)
f1,f2,f3,f4,f5,f6 (multiples must be separated by a comma and no
space)
yyyy-mm-dd f1 (must be a space between the date and the first
footnote reference)
yyyy-mm-dd f1,f2

or just a date by itself

Again, sorry I wasn't clearer in my inital question.

Tom Ogilvy wrote:
Requires Excel 2000 or later.

Sub ABC()
Dim cell As Range, iloc As Long
Dim v As Variant, v1() As Variant
Dim s As String, dt As Date
Dim cnt As Long, i As Long
Dim lFNote As Long, ss As String
For Each cell In Selection
ss = Replace(Application.Trim(cell.Value), " ", ",")
iloc = InStr(1, ss, ",", vbTextCompare)
If iloc < 0 Then
v = Split(ss, ",")
dt = 0
cnt = 0
ReDim v1(1 To 1)
For i = LBound(v) To UBound(v)
s = Trim(v(i))
If IsDate(s) Then
dt = CDate(s)
ElseIf s Like "[Ff]#*" Then
cnt = cnt + 1
ReDim Preserve v1(1 To cnt)
v1(cnt) = CLng(Right(s, Len(s) - 1))
End If
Next
s = Format(dt, "mm/dd/yy")
For i = LBound(v1) To UBound(v1)
s = s & " " & v1(i)
Next
Debug.Print s
ElseIf IsDate(cell.Value) Then
dt = CDate(cell.Value)
Debug.Print dt
ElseIf Trim(cell.Value) Like "[Ff]#*" Then
s = Trim(cell.Value)
lFNote = CLng(Right(s, Len(s) - 1))
Debug.Print lFNote
End If
Next
End Sub

separates things out. I don't know what you want to do with the results.

Make the immediate window visible in the VBE (view=Immediate window in the
VBE) , select your cells, then run the macro.

--
Regards,
Tom Ogilvy




wrote in message
ups.com...
Should I check the cell contents as a string and extact any text like,
f1 etc., and then check the remaining string with isdate?

Something like that maybe?

Ron Rosenfeld wrote:
On Mon, 18 Sep 2006 12:28:01 -0700, Tom Ogilvy
wrote:

I'll let Ron give you a regular expressions solution since he will
whether I
answer or not.

And I was hoping you'd answer with a non-regular expression solution :-)
--ron