?
Solved

Expand macro to combine columns

Posted on 2011-03-13
5
Medium Priority
?
336 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
[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
  • 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 2000 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

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

777 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