所以我需要找到每年每个月的最高价格和最低价格。
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
我最大的问题是试图让过滤器工作,我的数据以这种方式格式化
2012 年 10 月 26 日 61.66 2012 年 10 月 25 日 61.6