Solved

Macro to pull out specific data over multiple sheets

Posted on 2013-11-03
4
564 Views
Last Modified: 2013-11-05
Table example
Hi all,

Imagine I have a table like the attached - and several tables across multiple tabs.

In the first tab - I can have a macro button called say - 08/11/2013

Clicking this would create a new tab, labelled 08/11/2013, and would contain any line from tables such as the attached, whose dates are covering the period of the 8th November.

Either starting, in progress (for example the 8th falls between the Start and End dates) or ending.

Is there a good macro way of doing this? autofiltering creates a bit of a mess of it!
0
Comment
Question by:HuyenDoThanh
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Robberbaron (robr)
Comment Utility
yes can be done...

1/ please post a small 10 line sample of data.
2/ how would we know what to put on the button.  do you want this selected or typed into call.  eg would be better to a have a button label <Process Date> with a cell holding desired date.

3/ how would the macro know what sheets to interogate ?  (each table is on a separate sheet ?)  
4/ how are the sheets named?  is the datatable always in the same location on the sheet ?
0
 

Author Comment

by:HuyenDoThanh
Comment Utility
Okay I apologise, I was posting I guess for a general rather than specific solution and I then I could fit that for my purpose exactly.

https://dl.dropboxusercontent.com/u/15096766/Example.xlsm

I've attached an example.

So in the cutover tab, clicking on one of those dates, say the 09/11/2013 (i've made it a shape so you can assign macros to it) - will go through each sheet (here I have environments and data migration as examples with 10 lines each) and finally generate a new table/sheet.

The new sheet will be named 09/11/2013, and will contain a table listed all the Activities that are starting, running, or ending on the 9th.

Does that help?

There will be more sheets than just two, but they will be static once there.
0
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
Comment Utility
ok. try this...

1/ sheet names cant use "/" character. so i use -
2/ I also added "cutover" to the front of name to make it easy to tell what sheets to process.  ie all not "cutover"
3/ I also use a text month to remove any possible confusion regarding date.
4/ I also used a cell to hold target date, and a button to process. because it was easier for me....

there is no indication on the output where the activity came from., i guess you have other means.
Sub ProcessCutover()
    Dim checkdate As Date
    Dim cursheet As Worksheet, outputSheet As Worksheet
    Dim datacell As Range, outputrow As Range
    
    'get the date
    checkdate = Range("CutoverDate")
    
    'create new sheet. check not exist
    Set outputSheet = ActiveWorkbook.Sheets.Add(After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count))
    On Error Resume Next
    outputSheet.Name = "Cutover-" & Format(checkdate, "dd-mmm-yyyy")
    If Err.Number > 0 Then
        'there is duplicate name
        MsgBox "Duplicate named sheet", vbAbortRetryIgnore
        'what to do now ?????
    End If
    
    Set outputrow = outputSheet.Range("A1")
    
    'for each sheet not a dated one.
    For Each cursheet In ActiveWorkbook.Sheets
        If InStr(cursheet.Name, "Cutover") = 0 Then
            Set datacell = cursheet.Range("A2")
            
            'for each row of data
            Do While datacell.Value <> ""
    
              'if checkdate is in range
              If datacell.Offset(0, 1).Value <= checkdate And datacell.Offset(0, 2).Value >= checkdate Then
                 'copy row to output
                 datacell.EntireRow.Copy outputrow
                 Set outputrow = outputrow.Offset(1, 0)
              End If
              'move to next data row
              Set datacell = datacell.Offset(1, 0)
           Loop  'next row
       End If
    Next cursheet
End Sub

Open in new window

Example1a.xlsm
0
 

Author Closing Comment

by:HuyenDoThanh
Comment Utility
That is perfect, thank you very much.

I added in some stuff at the end to give it the same format as the other sheets - with a row of headings etc and to autofit the cells so it looks great now.

I just need to replicate the macro for two months of dates now, woo...

Either way it works great so thanks for the help.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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.

744 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

16 Experts available now in Live!

Get 1:1 Help Now