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
Solved

Expand macro

Posted on 2011-03-12
2
310 Views
Last Modified: 2012-05-11
The attached sheet and macro code creates output tabs as if both input tabs (pm and rm) were always going to have the names pm and rm.   I am wanting the macro to run against whatever tab is currently active only, regardless of the name.  In the output tab, I also need two (2) new empty columns (between C&D) named LegType, and Leg#, respectively.  Assistance is greatly appreciated.
Public Sub CopyTradeHistory()
  Dim wks As Worksheet
  Dim vSheets() As Variant
  Dim vSheetname As Variant
  Dim rngSrc As Range
  vSheets = Array("pm", "rm")
  On Error Resume Next
  Application.DisplayAlerts = False
  Application.ScreenUpdating = False
  For Each vSheetname In vSheets
    Set wks = ActiveWorkbook.Worksheets(vSheetname)
    Set rngSrc = wks.Cells.Find("Account Trade History")
    Set rngSrc = wks.Range(rngSrc, rngSrc.End(xlDown).End(xlDown).Offset(0, 11))
    ActiveWorkbook.Worksheets(vSheetname & "_output").Delete
    Set wks = ActiveWorkbook.Worksheets.Add
    wks.Name = vSheetname & "_output"
    rngSrc.Copy wks.Range("A1")
  Next
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub

Open in new window

trade-macro-v2.1d.xlsm
0
Comment
Question by:rtod2
2 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 35117930
this should work
Option Explicit

Public Sub CopyTradeHistory()
  Dim wks As Worksheet
  Dim rngSrc As Range
  Dim strSheetname As String
  
  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")
  
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub

Open in new window

0
 

Author Comment

by:rtod2
ID: 35117956
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

792 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