Solved

MS Excel Lookup and Reporting with Buttons and Macro Features

Posted on 2012-04-05
5
376 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
Comment Utility
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
Comment Utility
Thanks Dave,

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

Accepted Solution

by:
dlmille earned 500 total points
Comment Utility
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
Comment Utility
Thanks again Dave!
0
 

Author Closing Comment

by:ckwillGWU
Comment Utility
Great work!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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.

771 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