Solved

Expand macro to combine columns

Posted on 2011-03-13
5
326 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

746 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

12 Experts available now in Live!

Get 1:1 Help Now