Solved

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

Posted on 2012-03-23
4
255 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 41

Accepted Solution

by:
dlmille earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for your help.
0
 
LVL 41

Expert Comment

by:dlmille
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article will show you how to use shortcut menus in the Access run-time environment.
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 will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

772 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

10 Experts available now in Live!

Get 1:1 Help Now