Solved

Macro to pull out specific data over multiple sheets

Posted on 2013-11-03
4
588 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
[X]
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
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
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…

728 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