Solved

MS Excel Lookup and Reporting with Buttons and Macro Features

Posted on 2012-04-05
5
386 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 42

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 42

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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