Solved

macro to extract section to output tab

Posted on 2011-03-11
7
414 Views
Last Modified: 2012-05-11
I need a macro that will run against either tab (pm or rm) and extract the Trade History section into an output tab as shown.
trade-macro-v2.1c.xlsm
0
Comment
Question by:rtod2
  • 3
  • 3
7 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 35116307
Please try this:

Option Explicit

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

0
 

Author Comment

by:rtod2
ID: 35116327
Perfect!  Thank you.

I was only wanting it to run against one or the other though.  I want to be 'able' to run against either sheet.
0
 
LVL 45

Expert Comment

by:aikimark
ID: 35116332
you can change it to do whatever you need.
0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:rtod2
ID: 35116366
How would I get it to give only one output depending on which sheet it was run against?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 35117851
* You would query the user for a sheet name (Inputbox
* You would assume that the activesheet.name is the sheet to be processed -- warning: you need to check to see that the activesheet.name is PM or RM.
* It shouldn't matter.  Let the code create both outputs and delete the one you don't want.
0
 

Author Comment

by:rtod2
ID: 35117904
Actually it really does matter for this.  I was asked to break it down into small pieces so to simplify what I am asking, I will just start referring to a single tab.  Here is the new question >>>  http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_26882640.html
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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 code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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.

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