Solved

Correct date format in macro

Posted on 2011-03-13
3
312 Views
Last Modified: 2012-05-11
Attached is a macro and sheet containing an output tab.  The macro output tab processes most of the dates correctly as they are formatted by an abbreviated month, followed by a four(4) digit year (i.e. Mar 2011).  This is precisely correct.  Some types of trades though have an actual date that is important also and so the formatting is not correct for those.  In the cases where there is an actual date in the Exp column (some of these are denoted in yellow), the format for them should be an abbreviate month, followed by a two (2) digit date, followed by a four (4) digit year (i.e. Mar 5 2011) with no commas or punctuation.  Assistance is greatly appreciated.  Both the macro and sheet are here.
Option Explicit

Public Sub CopyTradeHistory()
  Dim wks As Worksheet
  Dim rngSrc As Range
  Dim strSheetname As String
  Dim lastrow As Long
  
  On Error Resume Next
  Application.DisplayAlerts = False
  Application.ScreenUpdating = False
  
  Set wks = ActiveSheet
  strSheetname = wks.Name
  Set rngSrc = wks.Cells.Find("Account Trade History")
  Set rngSrc = wks.Range(rngSrc, rngSrc.End(xlDown).End(xlDown).Offset(0, 11))
  ActiveWorkbook.Worksheets(strSheetname & "_output").Delete
  Set wks = ActiveWorkbook.Worksheets.Add
  wks.Name = strSheetname & "_output"

  rngSrc.Copy wks.Range("A1")
  wks.Columns(3).Insert
  wks.Columns(5).Insert
  wks.Cells(2, 3).Value = "Strategy#"
  wks.Cells(2, 4).Value = "Strategy"
  wks.Cells(2, 5).Value = "Leg#"
  wks.Rows("1:2").Font.Bold = True
  lastrow = wks.Range("a" & 64000).End(xlUp).Row
  wks.Range("E3:E" & lastrow).Formula = "=IF(OR(H3<>H2,E2=""leg2""),""Leg1"",""Leg2"")"
  wks.Range("E3:E" & lastrow).Value = wks.Range("E3:E" & lastrow).Value
  wks.Range("C3:C" & lastrow).Formula = "=counta(B3:B$3)"
  wks.Range("C3:C" & lastrow).NumberFormat = "General"
  wks.Range("C3:C" & lastrow).Value = wks.Range("C3:C" & lastrow).Value
  wks.Range("I3:I" & lastrow).NumberFormat = "mmm yyyy"
  wks.Columns(3).Insert
  wks.Cells(2, 3).Value = "Position#"
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub

Open in new window

TradeHist-2.3b.xlsm
0
Comment
Question by:rtod2
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 35123687
rtod2,

>>the format for them should be an abbreviate month, followed by a two (2) digit date, followed by a four (4) digit year
>>(i.e. Mar 5 2011)


If you want a two-digit day, then shouldn't your example be:

Mar 05 yyyy

Try changing:

  wks.Range("I3:I" & lastrow).NumberFormat = "mmm yyyy"

Open in new window


to:

  wks.Range("I3:I" & lastrow).NumberFormat = "mmm dd yyyy"

Open in new window


Patrick
0
 

Author Comment

by:rtod2
ID: 35123751
Most of those cells I want in the "mmm yyyy" format but the ones that look like this >> http://screencast.com/t/Dy2FnVVX I would prefer to have in the "mmm dd yyyy" format.  I'm not sure how to differentiate.  Please have a look at the actual original input tab and macro if possible.
0
 

Author Comment

by:rtod2
ID: 35123981
I have re-examined this need and think it is a bad idea after all at this point.  Thanks for the assistance.  Here is the new question >> http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26883875.html
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question