Solved

Expand macro to combine columns

Posted on 2011-03-13
5
328 Views
Last Modified: 2012-05-11
I need the macro in the attached spreadsheet to combine columns (Exp, Strike, Type) into a single column.  Assistance is greatly appreciated.
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
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Makrini
ID: 35124099
TradeHist-2.3b-1-.xlsm

This should do that for you.  Not sure what you wanted the header called.

And good morning!
0
 

Author Comment

by:rtod2
ID: 35124126
It's GREAT to see you back!!  I'll be back in 30min.

That's interesting.  This is what yours looks like to me >>  http://screencast.com/t/dxHvdd3rzrto

This is what mine looked like before combining columns >> http://screencast.com/t/BzGVAZzU1uvj.  Notice that you have a strange date format or something.

Also, can we rename the Strategy column back to Spread and Strategy# back to Spread# respectively.  I never should have modified those column names, at least not now.
0
 
LVL 10

Accepted Solution

by:
Makrini earned 500 total points
ID: 35124190
TradeHist-2.3b-1-.xlsm

This should fix the date format and the column names

Did you find out what you wanted to do with the garbage date data?
0
 

Author Closing Comment

by:rtod2
ID: 35124313
Perfect!  In answer to your question, it is a quarterly and having it different serves to help one realize what it is.  I think the best option might just be to leave it along.  Thank you for all your help.  Follow-up question on the way...
0
 

Author Comment

by:rtod2
ID: 35124335
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now