Solved

Pull fields from an Excel report and import them into another worksheet.

Posted on 2012-03-23
4
261 Views
Last Modified: 2012-03-24
Hello,

I have a report of about 1000 employees - the attached sample report has 5 employees.  Is it possible to massage the document to something like the attached target report?  

Please note that the "Accural Balance and Projections" line appears multiple times in the report in a irregular sequence.  

I think this one is very tough.  Any advise or feedback is greatly appreciated.  

Many Thanks.
sample-report.xls
target-report.xls
0
Comment
Question by:nav2567
  • 2
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
dlmille earned 500 total points
ID: 37760061
As requested.  Parse source sheet, create Target sheet and output.

code:
Option Explicit
Const strMatch = "Carryover Vacation,Lifetime PTO,Personal,Sick,Vacation"
Sub generateTargetReport()
Dim wkb As Workbook
Dim wksSrc As Worksheet
Dim wksTgt As Worksheet
Dim rng As Range
Dim r As Range
Dim lastRow As Long
Dim rOutput As Range
Dim bFound As Boolean

    Set wkb = ThisWorkbook
    Set wksSrc = wkb.ActiveSheet
    
    On Error Resume Next
    Set wksTgt = wkb.Worksheets("Target")
    If Err.Number <> 0 Then
        Set wksTgt = wkb.Worksheets.Add(after:=wkb.Worksheets(wkb.Worksheets.Count))
        wksTgt.Name = "Target"
    End If
    On Error GoTo 0
    
    wksTgt.Cells.Clear
    
    Set rOutput = wksTgt.Range("A2")
    
    lastRow = wksSrc.Range("B" & wksSrc.Rows.Count).End(xlUp).Row
    
    Set rng = wksSrc.Range("B1:B" & lastRow)
    
    For Each r In rng
        If r.Value = "Carryover" Then Stop
        If r.Value <> vbNullString Then
            If InStr(r.Value, ",") <> 0 Then 'found a person
                If bFound Then Set rOutput = rOutput.Offset(2, 0)
                rOutput.Resize(1, 2).Font.Bold = True
                rOutput.Value = r.Value
                rOutput.Offset(, 1).Value = r.Offset(0, 7).Value
                rOutput.Offset(, 15).Value = r.Offset(0, 7).Value
                rOutput.Offset(, 15).Font.Bold = True
                bFound = True
                Set rOutput = rOutput.Offset(1, 0)
            ElseIf bFound And InStr(strMatch, r.Value) <> 0 Then 'processing people and matches
                If r.Value = "Carryover Vacation" Then
                    rOutput.Value = "Carryover"
                Else
                    rOutput.Value = r.Value
                End If
                rOutput.Offset(, 1).Value = r.Offset(, 6).Value
                Set rOutput = rOutput.Offset(1, 0)
            End If
            
        End If
    Next r
End Sub

Open in new window


See attached demonstration workbook.

Dave
sample-report.xls
0
 

Author Comment

by:nav2567
ID: 37760442
Hi Dlmille, thank you very much.  From what I have seen, this is doable.  Unfortunately, I am not an advance user in Excel.  Would you just give me some high level of steps I need to do to customize my original spreadsheet, and I probably will have to do my own research to understand them.  

Thank you again.
0
 

Author Closing Comment

by:nav2567
ID: 37761087
Thanks for your help.
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37761493
As long as the report is in the exact same format, all you need to do is hit ALT-F11 and add a public module to your workbook (in the VBA editor, see VBAProject(your workbook name - right click and INSERT-Module) then copy/paste the code in.  To run the macro (which runs on the active sheet) just hit Tools->Macros->generateTargetReport()->Run, or DeveloperRibbon->Macros->generateTargetReport()->Run.

An alternative would be to copy/paste your report into the uploaded workbook that already has the macros in it, then run the macro as described, above.

Cheers,

Dave
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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…

840 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