简体   繁体   中英

How to use VBA Excel Code to display a pop-up message to users that have out of date information

I want to have a pop-up appear when the spreadsheet is opened.

Each tech is required to log their issues in the spreadsheet. When the sheet is opened, I would like it to check for the user's username against the issue list and alert them of any that have exceed their time estimate. If any issue is beyond the estimated time frame, I want the sheet to pop-up a dialog box or windows saying you have Issues A,B,C,, and that those issues need to be closed or extended.

  • Col A is issue Number.
  • Col B is the date an issue was started.
  • Col C is the number of Days expected for issue to be resolved (30, 60, 90, X - using a dropdown menu for these options. X Meaning it is going to be an extended time frame; unknown at entry.)
  • Col D is the status either Closed or Open also controlled by dropdown.
  • Col E is the closure date which I'm already handling using a VBA code to auto-populate when closed is chosen from dropdown.
  • Col F is the name of the tech handling issue.

SS of Spreadsheet

Here is where I am with the code

    'DECLARE VARIABLE
        Dim x_matrix As Range
        Dim x_copyrange, sheet_name, issueString, currentTechName As String
        Dim x_step, x_fnl_row As Long
        Dim issIDCol, issStatCol, issTechCol, IssLogDateCol As Variant
        Dim IssExpClosCol As Variant
    'DEFINE VARIABLE
        sheet_name = "Log" 'PUT YOUR SHEET NAME
        issueString = "Alerts have been found to be late, Please extend or Close"
        issIDCol = Columns(1)  'Put Your Report ID Column
        currentTechName = Application.UserName 'returns username currently using sheet
        issTechCol = Columns(6)  'The Tech name column
        issStatCol = Columns(4) ' The Issue Status Column
        IssLogDateCol = Columns(2) 'Column where you are logging the date issue reported
        IssExpClosCol = Columns(3)  '30, 60, 90, X Column
        
        'CREATE MATRIX
            x_fnl_row = Worksheets(sheet_name).Cells(Rows.Count, 1).End(xlUp).Row
            'Find last row of Log # Col & used to make the loop larger each time an entry is added
            Let x_copyrange = "a" & 1 & ":" & "F" & x_fnl_row
            'sets a1 to bottom of last entry in F as a range
            Set x_matrix = Worksheets(sheet_name).Range(x_copyrange)
            'Sets the parameters for X_Matrix as a range on the worksheet
    
    'LOOP TO
        x_step = Rows(2) 'Skips the header row at the top of sheet so loop will not loop through row 1
        Do While x_step <= x_fnl_row 'Sets the loop to run through the range as long as the final row is farther down then the first row
            'This is your Loop
            'Make your Conditions Here
            'Issue is open and issue date starting is greater than expected closure date.
            'Tech Names Match
            
            
            If x_matrix(x_step, IssExpClosCol) <> "PPSC Closure" Then ' Xmatrix is the whole range (Xstep is the rows of range, tells it what col to search)
                If x_matrix(x_step, issTechCol) = currentTechName And _
                x_matrix(x_step, issStatCol) = "OPEN" And _
                Now() > x_matrix(x_step, IssLogDateCol) + x_matrix(x_step, IssExpClosCol) _
                Then
                    issueString = issueString + x_matrix(x_step, issIDCol) + ", "
                End If
            End If
        x_step = x_step + 1
        Loop
        
        MsgBox (issueString)
End Sub



I posted some code below that works based on the how i set up my spreadsheet columns (see attached picture). I think this might be what you are asking for. Take a look see if it will work for you.

Sub standard()
    'DECLARE VARIABLE
        Dim x_matrix, y_matrix, z_matrix As Range
        Dim x_copyrange, y_copyrange, z_copyrange, sheet_name, issueString, currentTechName As String
        Dim x_step, y_step, z_step, x_fnl_row, y_fnl_row, z_fnl_row As Integer
        Dim issIDCol, issStatCol, issTechCol, IssLogDateCol, IssExpClosCol As Integer
        
    'DEFINE VARIABLE
        sheet_name = "Log" 'PUT YOUR SHEET NAME
        issueString = "Alerts have been found to be late, Please extend or Close"
        issIDCol = 1 'Put Your Report ID Column
        currentTechName = Application.UserName  'Sound like you need to add your VBA here to know the tech using the sheet
        issTechCol = 6 'The Tech name column
        issStatCol = 4 ' The Issue Status Column
        IssLogDateCol = 2 'Column where you are logging the date issue reported
        IssExpClosCol = 3 '30, 60, 90, X Column
        
        'CREATE MATIX
            x_fnl_row = Worksheets(sheet_name).Cells(Rows.Count, issIDCol).End(xlUp).Row
            Let x_copyrange = "a" & 1 & ":" & "e" & x_fnl_row
            Set x_matrix = Worksheets(sheet_name).Range(x_copyrange)
    
    'LOOP TO
        x_step = 2 'I am guessing you have a Header Row so start at 2
        Do While x_step <= x_fnl_row
            'This is your Loop
            'Make your Conditions Here
            'Issue is open and issue date starting is greater than expected closure date.
            'Tech Names Match
            If x_matrix(x_step, IssExpClosCol) <> "X" Then
                If x_matrix(x_step, issTechCol) = currentTechName And _
                x_matrix(x_step, issStatCol) <> "Closed" And _
                Now() > x_matrix(x_step, IssLogDateCol) + x_matrix(x_step, IssExpClosCol) _
                Then
                    issueString = issueString + x_matrix(x_step, issIDCol) + ", "
                End If
            End If
        x_step = x_step + 1
        Loop
        
        MsgBox (issueString)
End Sub

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM