我想做的是拿出我的预算表并按特定顺序对其进行排序。这正是我所拥有的:
A 列 = 预算项目名称(账单和支付)
B 列 = 该项目到期的月份中的哪一天。
C 列 = 该项目的金额。
我想创建一些VBA
代码,当按下按钮时,它将从这些列中获取该信息,并在 B 列中按天排序,如下所示:
1 - PayDay - 1000
4 - Cell Phone - 75
5 - Mortgage - 1350
编辑:
我一直在研究这个 VBA。只需要弄清楚如何放入排序函数,以便按天列对我的结果进行排序。
Sub CreateList()
' Clear the current records
currentRow = 2
While currentRow < 200
If IsEmpty(Worksheets("Jan").Cells(currentRow, 9)) Then
GoTo Generate
End If
Worksheets("Jan").Cells(currentRow, 9).Value = ""
Worksheets("Jan").Cells(currentRow, 10).Value = ""
Worksheets("Jan").Cells(currentRow, 11).Value = ""
Worksheets("Jan").Cells(currentRow, 12).Value = ""
currentRow = currentRow + 1
Wend
Generate:
' Generate new list
titleCol = 1
dayCol = 2
amountCol = 3
currentListRow = 2
currentSheet = 1
While currentSheet < 2
currentRow = 7
cellVal = ""
While currentRow < 800
cellVal = Worksheets("Jan").Cells(currentRow, dayCol).Text
If Not IsEmpty(cellVal) Then
If Not cellVal = "0" Then
If Not cellVal = "" Then
If Not cellVal = "Due Date" Then
' Set vals in list cells
Worksheets("Jan").Cells(currentListRow, 10).Value = Worksheets("Jan").Cells(currentRow, dayCol).Text
Worksheets("Jan").Cells(currentListRow, 9).Value = Worksheets("Jan").Cells(currentRow, titleCol).Text
Worksheets("Jan").Cells(currentListRow, 11).Value = Worksheets("Jan").Cells(currentRow, amountCol).Text
currentListRow = currentListRow + 1
End If
End If
End If
End If
currentRow = currentRow + 1
Wend
currentSheet = currentSheet + 1
Wend
End Sub