Solved

Correct date format in macro

Posted on 2011-03-13
3
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

726 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