从任务列表自动创build一个艾森豪威尔matrix

我想在Excel中自动执行待办事项列表,使用VBA创build一个艾森豪威尔matrix 。

我用以下方式构build了我的待办事项列表:

Task | Urgent | Important | done T1 | x | x | T2 | | x | T3 | x | | T4 | | | 

我能够在紧急和重要性上过滤我的任务列表,并排除表示为“已完成”的行。

我想创build我的matrix,看起来像这样:

 __________|IMPORTANT|NOT IMPORTANT URGENT | T1 | T3 ----------|---------|-------------- NOT URGENT| T2 | T4 

我不知道如何编写我的VBA,以便select我的过滤行,确定matrix的大小,并相应地填充它。

我正在尝试使用excel VBA中的range.count()属性来计算行数,但是我无法使T2和T4alignment。 而且,它也会每次复制“任务”标题。

我到目前为止的代码如下:

 Sub populate_matrix() Dim i As Integer ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=5, Criteria1:="=" ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=2, Criteria1:="<>" ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=3, Criteria1:="<>" Range("A1").Select Range(Selection, Selection.End(xlDown)).Select i = Range(Selection).Count Selection.Copy Sheets("work matrix").Select Range("B2").Select ActiveSheet.Paste Sheets("tasks").Select ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=5, Criteria1:="=" ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=2, Criteria1:="<>" ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=3, Criteria1:="=" Range("A1").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Sheets("work matrix").Select Range("B" & i).Select ActiveSheet.Paste Sheets("tasks").Select ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=5, Criteria1:="=" ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=2, Criteria1:="<>" ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=3, Criteria1:="=" Range("A1").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Sheets("work matrix").Select Range("c2").Select ActiveSheet.Paste Sheets("tasks").Select ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=5, Criteria1:="=" ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=2, Criteria1:="=" ActiveSheet.Range("$A$1:$E$55").AutoFilter Field:=3, Criteria1:="=" Range("A1").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Sheets("work matrix").Select Range("C" & i).Select ActiveSheet.Paste 

结束小组

在OP代码更新后编辑

你可以试试这个

 Option Explicit Sub main2() Dim EisenTable As Range Set EisenTable = Worksheets("work matrix").Range("B2:C3") With Worksheets("tasks") With .Range("D1", .Cells(.Rows.Count, "A").End(xlUp)) EisenTable.Cells(1, 1) = CountX(.Cells, 2, 3, "x", "x") EisenTable.Cells(1, 2) = CountX(.Cells, 2, 3, "x", "<>x") EisenTable.Cells(2, 1) = CountX(.Cells, 2, 3, "<>x", "x") EisenTable.Cells(2, 2) = CountX(.Cells, 2, 3, "<>x", "<>x") End With End With End Sub Function CountX(rng As Range, col1 As Long, col2 As Long, crit1 As String, crit2 As String) As String Dim cell As Range Dim iVal As Long With rng .AutoFilter Field:=col1, Criteria1:=crit1 .AutoFilter Field:=col2, Criteria1:=crit2 If Application.WorksheetFunction.Subtotal(103, .Cells) > 1 Then With .Resize(.Rows.Count - 1, 1).Offset(1).SpecialCells(xlCellTypeVisible) ReDim vals(1 To .Count) As String For Each cell In .Cells iVal = iVal + 1 vals(iVal) = cell.Value Next End With CountX = Join(vals, ",") End If .Parent.AutoFilterMode = False End With End Function