在Excel中dynamic重新编号列表

在Excel中,是否有办法dynamic更新任务列表的优先级? 例如,如果您有一个优先级为1,5,3,2,4的列,并且用户添加了一个具有新任务的新行并将其优先级分配为1,则列表将更新为2,6,4,3 ,5,1?

还是有一些其他的(更好的?)这样做? 我宁愿不必sorting列表,然后每次添加或删除新任务时手动更改编号。 另外,我不认为使用电子表格的人会这样做。

看看下面的代码。

Private Sub Worksheet_Change(ByVal Target As Range) Dim rngPriorityList As Range Dim lNewValue As Long Dim myCell As Range If IsNumeric(Target.Value) Then 'Only run if the a number was entered Set rngPriorityList = ThisWorkbook.Names("priority").RefersToRange 'the named range for the task list If Not Intersect(Target, rngPriorityList) Is Nothing Then 'Only run the following in the cell being updated was in the priority list range For Each myCell In rngPriorityList.Cells 'Loop through the priority list range If myCell.Value = Target.Value _ And myCell.Address <> Target.Address Then 'Finding cells with the same value, excluding the cell being changes myCell.Value = myCell.Value + 1 'Increment the prioriry by 1 End If Next myCell End If End If End Sub 

我会倾向于VBA的答案,但我发现公式和列的添加做你需要没有macros。 看下面的图片

为了使这个工作从一个增加到另一个,在添加每个新任务之后,您必须在E:F列中复制已sorting的任务列表,将值粘贴到A3中,并删除B2和C2中的值。 然后,您需要将列表拖到C:F列底部,因为列表只是变长了。

这是我可以看到在单元格公式中做的最大的问题,更新需要复制粘贴删除。

根据设置优先级公式动态更改编号列表根据“设置优先级结果”动态更改编号列表