簡體   English   中英

如何使用 VBA Excel 代碼向擁有過期信息的用戶顯示彈出消息

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

我想在打開電子表格時出現一個彈出窗口。

每個技術人員都需要在電子表格中記錄他們的問題。 當工作表打開時,我希望它根據問題列表檢查用戶的用戶名,並提醒他們任何超過他們估計時間的用戶名。 如果任何問題超出了估計的時間范圍,我希望工作表彈出一個對話框或窗口,說明您有問題 A、B、C,並且這些問題需要關閉或擴展。

  • Col A 是問題編號。
  • Col B 是問題開始的日期。
  • Col C 是問題解決的預期天數(30、60、90、X - 使用這些選項的下拉菜單。X 意味着這將是一個延長的時間范圍;進入時未知。)
  • Col D 是 Closed 或 Open 狀態,也由下拉菜單控制。
  • Col E 是我已經使用 VBA 代碼處理的關閉日期,以便在從下拉列表中選擇關閉時自動填充。
  • Col F 是技術處理問題的名稱。

電子表格SS

這是我使用代碼的地方

    '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



我在下面發布了一些代碼,這些代碼基於我設置電子表格列的方式(見附圖)。 我想這可能就是你所要求的。 看看它是否適合你。

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

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM