?
Solved

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

Posted on 2012-03-23
4
Medium Priority
?
270 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
[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 42

Accepted Solution

by:
dlmille earned 2000 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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

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