Solved

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

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Outlook Free & Paid Tools
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!
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

733 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