因此,我需要找到每年每個月的最高價格和最低價格。按月和年篩選excel電子表格
Sub Anaylze()
Dim datemonthcount As Long
Dim dateyearcount As Long
Dim yearcount As Long
Dim month As Long
Dim yearstart As Long
Dim maxprice As Long
Dim minprice As Long
Dim rowprice As Long
Dim percentchange
Dim counterlong As Integer
rowprice = 1
yearstart = 2002
counterlong = 0
Range("A1").Select
Do Until IsEmpty(ActiveCell) Or ActiveCell.Value = 0 Or IsNumeric(ActiveCell) = False
counterlong = counterlong + 1 'Increments the counter
If year(ActiveCell.Text) <> year((ActiveCell.Offset(-1, 0).Text)) Then
dateyearcount = dateyearcount + 1
End If
ActiveCell.Offset(1, 0).Select ' Step down 1 row from present location.
Loop
For yearcount = 0 To dateyearcount
For month = 1 To 12
'Range("A1", "B" & counterlong).AutoFilter Field:=1, Criteria1:=">=" & month & "/01/" & yearstart, Operator:=xlAnd, Criteria2:="<=" & month & "/31/" & yearstart
maxprice = WorksheetFunction.Max(Range("A1", "B" & counterlong).AutoFilter(Field:=1, Criteria1:=">=" & month & "/01/" & yearstart, Operator:=xlAnd, Criteria2:="<=" & month & "/31/" & yearstart))
minprice = WorksheetFunction.Min(Range("A1", "B" & counterlong).AutoFilter(Field:=1, Criteria1:=">=" & month & "/01/" & yearstart, Operator:=xlAnd, Criteria2:="<=" & month & "/31/" & yearstart))
Cells(rowprice, "g") = maxprice
Cells(rowprice, "h") = minprice
rowprice = rowprice + 1
Next
yearstart = yearstart + yearcount
Next
End Sub
我最大的問題是試圖讓過濾器的工作,我的數據以這種方式被格式化
10/26/2012 61.66 10/25/2012 61.6
爲什麼不創建一個支點? – nutsch
nutch是現貨。你正在反思這一點。 – ApplePie