'How do I select specific rows of a change log (VBA) based on criteria to be displayed in another table?
I'm very new to VBA and have been trying to code a large table which populates as changes are made to a main dashboard. It should populate each row with the date/time, user, change type, project #, old/new values, and notes on why...
I have gotten far enough to actually have this portion functioning although I am running into issues when trying to display certain rows based on criteria. For example one of my sheets displays project specific information based on the project number selected from a drop-down. Is it possible to have this also fetch all of the change log entries related to this project and display them in a table on that sheet?
Also I have a main sheet that I want to display only the last week of changes.
Here is the code I have so far:
Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("D10:W100")) Is Nothing Then
If Target.Count > 1 Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End
End If
If ActiveSheet.Name = "Tender-Engineering" Then
Range("U2").Value = Target.Address
Range("U6").Value = InputBox("Please provide reasoning for the proposed change.", "Notes", "Type here")
AddToLog
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("D10:W100")) Is Nothing Then
Range("U3").Value = Target.Value
Range("U4").Value = Target.Row
Range("U5").Value = Target.Column
End If
End Sub
Sub AddToLog()
Dim ActRow, Row, Column, LogRow As Long
Dim changeType As String
With Sheet4
ActRow = .Range("U2").Value
LogRow = Sheet2.Range("E9999").End(xlUp).Row + 1
Sheet2.Range("E" & LogRow).Value = Now
Sheet2.Range("F" & LogRow).Value = Application.UserName
Sheet2.Range("G" & LogRow).Value = .Range("U2").Value
Row = .Range("U4").Value
Sheet2.Range("H" & LogRow).Value = .Range("A" & Row).Value
Column = .Range("U5").Value
If Column >= 4 And Column <= 5 Then
changeType = "Management"
ElseIf Column >= 6 And Column <= 18 Then
changeType = "Schedule"
ElseIf Column >= 19 And Column <= 23 Then
changeType = "Budget"
End If
Sheet2.Range("I" & LogRow).Value = changeType
Sheet2.Range("J" & LogRow).Value = .Range("U3").Value
Sheet2.Range("K" & LogRow).Value = .Range(.Range("U2").Value).Value
Sheet2.Range("L" & LogRow).Value = .Range("U6").Value
End With
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
