RE: Syntax to combine MID() and FIND("LastPost:") to extract the Last

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi J.P.

Because it appears that you have a colon after Last post, the position of
the colon can be returned with the InstrRev function and subtract that from
the total length of the string to find how many characters are required in
the Right function to return the date.

DateValue can then be used to return an actual date. Because it is an actual
date, it will sort in either Ascending or Decending order of the dates and
there is no need to format as Y/M/D. However, I have included a line to show
you how to code the formatting of the date column. Edit the part between the
double quotes to change the format to any valid date format.

Note that a space and underscore at the end of a line is a line break in an
otherwise single line of code.

Also it will not surprise me if someone posts an answer with a formula on
the worksheet without the the VBA code.

Sub PostDate()
Dim sht As Worksheet
Dim rng As Range
Dim cel As Range
Dim strDate As String

Set sht = Sheets("Sheet1")

'Cells(2, "A") assumes you have column headers
'and data actually starts on row 2.
With sht
Set rng = .Range(.Cells(2, "A"), _
.Cells(.Rows.Count, "A").End(xlUp))

'Edit the date format to whatever suits you.
.Columns(2).NumberFormat = "mm/dd/yyyy"
End With

For Each cel In rng
strDate = Trim(Right(cel.Value, _
Len(cel.Value) - _
InStrRev(cel.Value, ":")))

cel.Offset(0, 1) = DateValue(strDate)
Next cel

End Sub



--
Regards,

OssieMac


.



Relevant Pages

  • Re: Setting field properties in code
    ... format that the user has defined in the Windows Control Panel, ... >> Sub StandardProperties(strTableName As String) ... >> Dim tdf As DAO.TableDef 'Table nominated in argument. ... >> Dim ind As DAO.Index ...
    (comp.databases.ms-access)
  • Re: Conditional format problem
    ... an Excel 5.0/95 format file, ... Anyone know how to save in a later Excel format from Access? ... Dim oXL As Object ... Dim strCondition1 As String ...
    (microsoft.public.excel.programming)
  • Re: Mail Merge HTML Format Word 2002 XP SP3
    ... HTML format as you have no control over how the recipient reads them. ... 'Creates a new e-mail item and modifies its properties. ... Dim olApp As Outlook.Application ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Generating a column based on import file name
    ... is d/m/yy as opposed to the format shown. ... Dim lReturn As Long ... .TextFilePlatform = xlWindows ... importing. ...
    (microsoft.public.excel.programming)
  • Re: tab in userform locks program
    ... > I am a VBA newbie and have not been using DIM in my code so it is ... declare a variable at the top of a standard module using Private (module ... You may notice that I used Format$ instead of Format. ... but Format$ returns a String whereas ...
    (microsoft.public.excel.programming)