在VBA中使用命名范围创建动态优先级列表

在VBA中使用命名范围创建动态优先级列表,vba,Vba,我试图根据任务的当前状态列出任务列表的前5个优先级,我使用了一些for循环和if函数来实现这一点。但是,我使用的是一个命名范围中的状态列表(它作为使用sumproduct函数的单元格函数工作),但是当我运行代码时,当单元格等于列表中的值时,它不会注册 “Priorities_Team”是一个命名范围,由大约6个不同的单元格组成,但这需要能够更改,因为将来可能会有更多或更少的单元格,这就是我使用命名范围的原因 我还尝试用命名范围替换静态范围,但这无助于解决这种情况 在VBA中编写函数的方式是否存在

我试图根据任务的当前状态列出任务列表的前5个优先级,我使用了一些for循环和if函数来实现这一点。但是,我使用的是一个命名范围中的状态列表(它作为使用sumproduct函数的单元格函数工作),但是当我运行代码时,当单元格等于列表中的值时,它不会注册

“Priorities_Team”是一个命名范围,由大约6个不同的单元格组成,但这需要能够更改,因为将来可能会有更多或更少的单元格,这就是我使用命名范围的原因

我还尝试用命名范围替换静态范围,但这无助于解决这种情况

在VBA中编写函数的方式是否存在问题

Sub Macro1()

Dim i As Integer
Dim Num_Cells As Integer
Dim Running_Total As Integer
Dim i_Item_No As String
Dim i_Description As String
Dim i_Current_Status As String

Num_Cells = WorksheetFunction.CountA(Range("A2:A1000"))

Running_Total = 1

For i = 2 To Num_Cells
    Sheet1.Select
    If Running_Total < 6 Then
        i_Item_No = Cells(i, 1).Value
        i_Description = Cells(i, 2).Value
        i_Current_Status = Cells(i, 3).Value
    
        If WorksheetFunction.SumProduct(--(Cells(i, 3).Value = Priorities_Team)) > 0 Then
            Running_Total = Running_Total + 1
            Sheet2.Select
            Cells(Running_Total, 1).Value = i_Item_No
            Cells(Running_Total, 2).Value = i_Description
            Cells(Running_Total, 3).Value = i_Current_Status
        End If
    End If
Next i
End Sub
Sub宏1()
作为整数的Dim i
将Num_单元格设置为整数
Dim Running\u总计为整数
Dim i_项目编号为字符串
作为字符串的Dim i_描述
Dim i_当前_状态为字符串
Num_Cells=WorksheetFunction.CountA(范围(“A2:A1000”))
总运行时间=1
对于i=2到Num_单元格
表1.选择
如果运行_总数小于6,则
i_Item_No=单元格(i,1).值
i_Description=单元格(i,2).值
i\u当前状态=单元格(i,3).值
如果WorksheetFunction.SumProduct(--(单元格(i,3).Value=Priorities\u Team))大于0,则
运行总数=运行总数+1
表2.选择
单元格(运行总数,1)。值=项目编号
单元格(运行总数,2)。值=i\U说明
单元格(运行总数,3)。值=当前状态
如果结束
如果结束
接下来我
端接头

此代码对我有效,但我无法使用命名范围来实现此目的

Sub Macro1()

Application.ScreenUpdating = False
Dim i As Integer
Dim Num_Cells As Integer
Dim i_Output As String
Dim Running_Total As Integer
Dim i_Item_No As String
Dim i_Description As String
Dim i_Current_Status As String
Dim x As Integer
Dim Team_Last_Status As String

'Getting the number of Tasks in the sheet
Num_Cells = WorksheetFunction.CountA(Range("A2:A1000"))

'Getting the number of status's in the list
Team_Last_Status = WorksheetFunction.CountA(Range("E3:E20"))

Running_Total = 1

For i = 2 To Num_Cells
    Sheet1.Select
    If Running_Total < 6 Then
        i_Item_No = Cells(i, 1).Value
        i_Description = Cells(i, 2).Value
        i_Current_Status = Cells(i, 3).Value
    
        For x = 1 To Team_Last_Status + 2
            If i_Current_Status = Cells(x, 5).Value Then
                    Running_Total = Running_Total + 1
                    Sheet2.Select
                    Cells(Running_Total, 1).Value = i_Item_No
                    Cells(Running_Total, 2).Value = i_Description
                    Cells(Running_Total, 3).Value = i_Current_Status
            End If
        Next x

    End If
Next i
Application.ScreenUpdating = True
End Sub
Sub宏1()
Application.ScreenUpdating=False
作为整数的Dim i
将Num_单元格设置为整数
Dim i_输出为字符串
Dim Running\u总计为整数
Dim i_项目编号为字符串
作为字符串的Dim i_描述
Dim i_当前_状态为字符串
作为整数的Dim x
Dim Team_Last_状态为字符串
'获取工作表中的任务数
Num_Cells=WorksheetFunction.CountA(范围(“A2:A1000”))
'获取列表中状态的数量
团队最后状态=工作表函数.CountA(范围(“E3:E20”))
总运行时间=1
对于i=2到Num_单元格
表1.选择
如果运行_总数小于6,则
i_Item_No=单元格(i,1).值
i_Description=单元格(i,2).值
i\u当前状态=单元格(i,3).值
对于x=1至团队最后状态+2
如果i_Current_Status=单元格(x,5)。那么
运行总数=运行总数+1
表2.选择
单元格(运行总数,1)。值=项目编号
单元格(运行总数,2)。值=i\U说明
单元格(运行总数,3)。值=当前状态
如果结束
下一个x
如果结束
接下来我
Application.ScreenUpdating=True
端接头