Solved

MS Excel Lookup and Reporting with Buttons and Macro Features

Posted on 2012-04-05
5
398 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
[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
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
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…

687 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