Solved

Expand macro to combine columns

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

770 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