iT邦幫忙

0

VBA 依日期排序資料

https://ithelp.ithome.com.tw/upload/images/20200115/20109231Enlg1T0FKY.png

請問如何依照第2列日期,以當日數據由小至大固定排序A4:?103資料,例如:
今天為1/15,巨集執行時排序A4:H103,排序方式為H欄數字由小至大排序
今天為1/16,巨集執行時排序A4:I103,排序方式為I欄數字由小至大排序
今天為1/17,巨集執行時排序A4:J103,排序方式為J欄數字由小至大排序

ps:每日皆會彙整數據後進行人工排序,希望可彙整數據後使用巨集自動排序,求解~~
測試檔https://drive.google.com/open?id=1EgS_Mn7V4Bozkp4DVENgl6muQADcjICx

你用錄製巨集試試看
錄製是醬,但我不知道怎麼固定依日期自動排序
Sub 巨集()
Range("A4:H103").Select
ActiveWorkbook.Worksheets("test").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("test").Sort.SortFields.Add Key:=Range("H4:H103"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("test").Sort
.SetRange Range("A4:H103")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
哈~~~結果我真的測試出來了耶!!!謝謝p大提示~~~~用錄製再修改已解決問題,謝啦
Sub 巨集()
Sheets("test").Select
Dim Column As Integer
Column = Application.Match(CLng(CDate(Date)), Sheets("test").Range("A2:MU2"), 0)
Range(Cells(4, 1), Cells(103, Column)).Select
ActiveWorkbook.Worksheets("test").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("test").Sort.SortFields.Add Key:=Range(Cells(4, Column), Cells(103, Column)), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("test").Sort
.SetRange Range(Cells(4, 1), Cells(103, Column))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答