View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Looking for custom date format

Rick, the sql data which gets extracted appears in certain cells, and
I'd like to leave those cells as the data display sensitive cells,
without adding another row or column to extract the date-text-date
format.


I have a possible idea for a macro function which could toggle the
display
back and forth between you number format and the month-year format, but I
would need to know what those "certain cells" are. Are they fixed in
number
(count)? How many of them are there? Are the contiguous?

Thanks for the 2nd pass on your formula, b t w. Regards.


Yeah, but I would go with either Peo's or Teethless mama's as they are
tighter.

Rick


Rick, the number of fields changes. They begin at E2, and go as far
right as the extracted data gets. The 10408, is a pivot table
extracted field(E2, and beyond where applicable).


We can work out the activation method later... for now, I just want to see
if this treatment is OK with you. Start a new workbook and put some of your
"date numbers" in cells E2, E3, E4, etc. for maybe 5 or 6 cells. Now, right
click the sheet's tab and select View Code from the popup window. Paste the
code below into the code window that appears. Now, return to your worksheet
and double click anywhere on the sheet and watch the cells you entered your
"date numbers" in. Double click the sheet again, and again, etc. If all went
right, you should be seeing the dates toggle back and forth between you
"date number" and the "friendly format" you asked for.

Rick


Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
Dim X As Long
Dim LastColumn As Long
Dim TempDate As Date
Dim DateCell As Range
Const DateRow As Long = 2
Const StartColumn As Long = 5
LastColumn = Cells(DateRow, 255).End(xlToLeft).Column
For X = StartColumn To LastColumn
Set DateCell = Cells(DateRow, X)
DateCell.NumberFormat = "@"
If DateCell.Text Like "1####" Then
TempDate = DateSerial(Mid$(DateCell.Text, 2, 2), _
Right$(DateCell.Text, 2), 1)
DateCell.NumberFormat = "mmm-yy"
DateCell.Value = TempDate
Else
DateCell.NumberFormat = "00000"
DateCell.Value = Format(DateCell.Value, "1yymm")
End If
Next
Cancel = True
End Sub