- 帖子
- 12
- 主題
- 4
- 精華
- 0
- 積分
- 54
- 點名
- 0
- 作業系統
- XP
- 軟體版本
- office 2003
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2012-6-13
- 最後登錄
- 2020-9-1
|
回復 2# GBKEE
不好意思,我仔細一看,這程式碼,是把每週五的開低收高秀出來,那我想把開盤價設在週一,最高最低是這在週所出現的數值,收盤當然週五最後的價格,我有看到對岸寫的程式碼,但我不知道要從而改起,請版主看看
Sub bwwweek()
‘建立新的工作表, 存放周数据
ActiveWorkbook.Sheets.Add after:=Worksheets(1)
Worksheets(1).Activate
‘把第一行数据存到变量,hand为行号,h为最高,l为最低,c为收盘,d为日期,vol为成交股数,amt为成交金额
Dim hand As Integer, h As Double, l As Double, _
c As Double, d As Date, o As Double, _
vol As Long, amt As Long
hand = 1
d = Worksheets(1).Cells(hand, 1).Value
‘交易第一天离开星期五有几天,n5计数器,fri储存星期五的日期
Dim n5 As Integer, md5 As Date
For n5 = 0 To 4
fri = d + n5
If Weekday(fri) – 1 = 5 Then
Exit For
End If
Next n5
‘第一周的行数,row1为本周第一交易日行数,row5为本周最后交易日行数, frim暂储存一周内交易日的数据, 用于和这周fri日期比较,大于fri即计算本周最后交易日行数
Dim row1 As Integer, row5 As Integer, frim As Date
row1 = 1
Dim n As Integer
For n = 1 To 6
If frim > fri Then
row5 = n – 1
Exit For
End If
frim = Worksheets(1).Cells((hand + n), 1).Value
Next n
‘把总共股票日K线原始数据的行数储存在rng变量
Dim rng As Integer
rng = Range(“A65536〃).End(xlUp).Row
Dim whand As Integer, wdate As Date
whand = 1
‘==========================================================
While row1 <= rng
‘——————————————————
If frim >= fri Or frim = 0 Then
‘把一周开盘,收盘,量等存入变量, 用于下面写入周的新工作表
wopen = Worksheets(1).Cells(row1, 2).Value
whigh = Application.WorksheetFunction.Max(Range(Cells(row1, 3), Cells(row5, 3)))
wlow = Application.WorksheetFunction.Min(Range(Cells(row1, 4), Cells(row5, 4)))
wclose = Worksheets(1).Cells(row5, 5).Value
wdate = Worksheets(1).Cells(row1, 1).Value
hand = row5 + 1
Worksheets(2).Cells(whand, 1).Value = wdate
Worksheets(2).Cells(whand, 2).Value = wopen
Worksheets(2).Cells(whand, 3).Value = whigh
Worksheets(2).Cells(whand, 4).Value = wlow
Worksheets(2).Cells(whand, 5).Value = wclose
whand = whand + 1
End If
‘————————————————————-
If hand <= rng And frim <> 0 Then
frim = Worksheets(1).Cells(hand, 1).Value
‘- - - - - - -
For n5 = 0 To 4
fri = frim + n5
If Weekday(fri) – 1 = 5 Then
Exit For
End If
Next n5
‘- - - - - - -
row1 = row5 + 1
‘///////////////////////////////////////////////////
For n = 1 To 6
If frim > fri Or frim = 0 Then
row5 = row5 + n – 1
Exit For
End If
frim = Worksheets(1).Cells((hand + n), 1).Value
Next n
‘//////////////////////////////////////////////////
Else
row1 = row5 + 1
End If
‘———————————————————–
Wend
‘===================================================
End Sub |
|