【问题标题】:How to use VBA Excel Code to display a pop-up message to users that have out of date information如何使用 VBA Excel 代码向拥有过期信息的用户显示弹出消息
【发布时间】:2020-09-03 22:53:33
【问题描述】:

我希望在打开电子表格时出现一个弹出窗口。

每位技术人员都需要在电子表格中记录他们的问题。打开工作表时,我希望它根据问题列表检查用户的用户名,并提醒他们任何超过他们估计时间的内容。如果有任何问题超出预计的时间范围,我希望工作表弹出一个对话框或窗口,说明您有问题 A、B、C,并且需要关闭或延长这些问题。

  • Col A 是问题编号。
  • Col B 是问题的开始日期。
  • Col C 是解决问题的预期天数(30、60、90、X - 使用这些选项的下拉菜单。X 表示这将是一个延长的时间范围;进入时未知。)
  • Col D 是关闭或打开的状态,也由下拉菜单控制。
  • Col E 是我已经使用 VBA 代码处理的关闭日期,以便在从下拉列表中选择关闭时自动填充。
  • Col F 是技术处理问题的名称。

SS of Spreadsheet

这里是我的代码

    '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



【问题讨论】:

  • 您需要在您的问题下单击edit 并在那里添加所有信息。如果您将问题的其他部分作为答案发布,它们将被审核流程删除,因为它们不是答案。

标签: excel vba date popup


【解决方案1】:

我在下面发布了一些代码,这些代码基于我设置电子表格列的方式(见附图)。我想这可能是你所要求的。看看它是否适合你。

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

【讨论】:

  • 运行时出现运行时错误 13 类型不匹配错误,只是想知道是不是因为您将 issstatcol 和 issIDcol 设置为整数而不是字符串?我使用 Application.Username 来提供使用电子表格的人员的姓名,以交叉引用技术名称。我想我明白你在这里所做的大部分事情让我有点糊涂
  • IssStatCol 和 issIDCol 应该是整数,它们是列位置,列 a=1, b=2....
  • 仍然让我很困惑,它会弹出运行时,当我调试它时,它卡在定义变量部分的 IssExpClosCol 上,我将它变成了一个变体并将其归结为 x_fnl_row=Worksheets(下一个创建 matix 之后的行)及其卡在那里的调试。我试图使用 ("A:A") 通过定义区域定义我的列然后太 Columns(1) 看看我是否定义错误但仍然没有。如果我的问题编号是 AA-####(带有破折号的字母和数字),这有关系吗
  • 分享您的电子表格和代码的图像,让我们开始工作吧。排除故障只需几分钟。
  • 试图分享代码和调试的片段,但显然有一些模组阻止了它,我可以尝试以非片段形式发布代码,看看情况如何
猜你喜欢
  • 2017-02-07
  • 1970-01-01
  • 2019-01-02
  • 1970-01-01
  • 2021-08-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多