Solved

Macro to pull out specific data over multiple sheets

Posted on 2013-11-03
4
581 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)
ID: 39621392
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
ID: 39621428
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
ID: 39623545
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
ID: 39623896
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Web Query 1 21
Highlight changing numbers in column 3 20
IDENTIFY THE CERO  OR ONE  OR BOTH IN AN NUMBER ?? 29 41
Excel VBA 30 40
: 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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

860 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