Solved

MS Excel Lookup and Reporting with Buttons and Macro Features

Posted on 2012-04-05
5
378 Views
Last Modified: 2012-04-05
Please help with the following; I've made all corrections that I was able to research and figure out on my own.

Issues 7-11 - LOOKUP and Running the Report - Working WorkBook Attached!

Issue 7: Need VB Script to Conduct the LOOKUP and Place proper values in the cell range of the report.

Issue 8: Need the VB Script that runs the report to automatically enter the date and time in this cell once it has completed running.

Issue 9 : Need this in the VB Script as the first (of two) drivers for pulling records from Sheet1 to put into this report with the correct corresponding header/row data.

Issue 10: Need this in the VB Script as the second (of two) drivers for pulling records from Sheet1 to put into this report with the correct corresponding header/row data.

Issue 11: Need the correct corresponding information from Sheet 1 auto-populated during the running of the reports, based off of the Upcoming and Past Due date Lookups.
0
Comment
Question by:ckwillGWU
  • 3
  • 2
5 Comments
 
LVL 41

Expert Comment

by:dlmille
ID: 37814690
These issues together may be a large scope than it should be for one E-E question which should take an expert up to 15-20 minutes to solve.  As a result, you may need to break these issues into pairs or something so they are more manageable.

For now, however, please upload your workbook so it can be assessed.

Cheers,

Dave
0
 

Author Comment

by:ckwillGWU
ID: 37814701
Thanks Dave,

Workbook Attached!
Test-Report-v2.xlsm
0
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
ID: 37814801
I see - this is scoped just right - its all about populating the report.  Thanks for posting the workbook.

Note, in the Desc sheet, VBA is not needed to post the last report run, as that data is already on the Report sheet, so a formula should suffice, correct?

Please review.

Here's the code (note, I changed your worksheet_change() code to deal with errors on the first if statement in the Sheet1 codepage - I did not dig into what that first features function is, but if there's an error, let it fall to the next).

Sheet1:
Dim PreviousValue

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Value <> PreviousValue Then
        Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
            Application.UserName & " changed cell " & Target.Address _
            & " from " & PreviousValue & " to " & Target.Value
    End If
    On Error GoTo 0
    If Target.Count > 1 Then Exit Sub 'not handling at the moment - this is if more than one cell is changed simultaneously
    If Not Intersect(Target, Range("F:F")) Is Nothing Then
        If Target.Value = "On Hold" And Left(Range("I" & Target.Row).Formula, 1) <> "=" Then 'prompt user
            MsgBox "Please Enter comments for On HOLD status"
        End If
    End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    PreviousValue = Target.Value
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, [G1:G2090]) Is Nothing Then Exit Sub
 
Cancel = True
UserForm1.Show
End Sub

Open in new window


In a public module for the Report - and I assigned the button to this macro (button on the Desc sheet):
Option Explicit
Const DataToReportOrder = "3,1,2,4,5,6,7,9"
Sub populateReport()
Dim wkb As Workbook
Dim wksReport As Worksheet
Dim wksData As Worksheet
Dim rng As Range
Dim r As Range
Dim lastRow As Long
Dim outCursor As Range
Dim strOut As String
Dim vDataToReportOrder
Dim vOutput
Dim l As Long

    Set wkb = ThisWorkbook
    Set wksReport = wkb.Worksheets("Report")
    Set wksData = wkb.Worksheets("Sheet1")
    
    lastRow = wksReport.Cells.Find(what:="*", LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlPrevious).Offset(1, 0).Row
    
    'clear current report
    wksReport.Range("A5:J" & lastRow).ClearContents
    Set outCursor = wksReport.Range("A5")
    
    'read data and populate report
    lastRow = wksData.Cells.Find(what:="*", LookIn:=xlValues, lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlPrevious).Offset(1, 0).Row
    
    'get column lined up between data and report sheet
    vDataToReportOrder = Split(DataToReportOrder, ",")
    
    Set rng = wksData.Range("H2:H" & lastRow)
    
    For Each r In rng
        If r.Value <> vbNullString Then
            If r.Value <= DateValue(Format(DateValue(Now()), "MM/DD/YY")) + 8 Then  'look at next 7 days and also past due
                If r.Value >= DateValue(Format(DateValue(Now()), "MM/DD/YY")) Then 'due today/future
                    outCursor.Value = r.Value 'due date
                Else 'past due
                    outCursor.Offset(, 1).Value = r.Value 'due date
                End If
                
                'create output string delimited by || for each column of output
                
                strOut = wksData.Cells(r.Row, CLng(vDataToReportOrder(LBound(vDataToReportOrder)))).Value
                
                For l = LBound(vDataToReportOrder) + 1 To UBound(vDataToReportOrder)
                        strOut = strOut & "||" & wksData.Cells(r.Row, CLng(vDataToReportOrder(l))).Value
                Next l
                
                'output the result
                vOutput = Split(strOut, "||")
                outCursor.Offset(, 2).Resize(1, UBound(vOutput) + 1).Value = vOutput
                Set outCursor = outCursor.Offset(1, 0)
            End If
        End If
    Next r
    
    wksReport.Range("B2").Value = Now
    
    wksReport.Activate
    
End Sub

Open in new window


See attached.  I started from the last solution I did for you so you have less to deal with pulling it all together.

Enjoy!

Dave
Test-Report-v3.xlsm
0
 

Author Comment

by:ckwillGWU
ID: 37814819
Thanks again Dave!
0
 

Author Closing Comment

by:ckwillGWU
ID: 37814823
Great work!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

867 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

21 Experts available now in Live!

Get 1:1 Help Now