|
Sub refresh()
Dim x As Long
Dim result, tmp
Dim str1 As String
x = Range("D2").Value
' Sheets(1).Cells(2, 4) = 0 '将显示正在运行的行数归零
str1 = ""
idx = x '确定 显示的第一行的行次
While Sheets(1).Cells(idx, 1) <> "" '如果股票代码行不为空就将股票代码传递给变量str1
str1 = str1 & Sheets(1).Cells(idx, 1).Value & ","
idx = idx + 1 '如果股票代码行不为空就将将行次向下移动一行
Wend
result = Jrj0DayData(str1)
DoEvents
For idx = 0 To UBound(result)
tmp = Split(result(idx), ",")
Select Case UBound(tmp)
Case 31: '源数据是每页31行
Select Case (tmp(3) - tmp(2)) '根据 收盘价与最新价的差 来分别执行下面的任务
Case Is > 0:
'如果新价格大于昨天的收盘价,那么就将该该行的C列:F列的字体颜色设置为红色,单元格内容显示为向上的箭头
Sheets(1).Range("C" & idx + x & ":F" & idx + x).Font.ColorIndex = 3
Sheets(1).Cells(idx + x, 3) = "↑"
Case 0:
'如果新价格等于昨天的收盘价,那么就将该该行的C列:F列的字体颜色设置为白色,单元格内容显示为一个线段
Sheets(1).Range("C" & idx + x & ":F" & idx + x).Font.ColorIndex = 1
Sheets(1).Cells(idx + x, 3) = "-"
Case Is < 0:
'如果新价格小于于昨天的收盘价,那么就将该该行的C列:F列的字体颜色设置为绿色,单元格内容显示为向下的箭头
Sheets(1).Range("C" & idx + x & ":F" & idx + x).Font.ColorIndex = 4
Sheets(1).Cells(idx + x, 3) = "↓"
End Select
Sheets(1).Cells(idx + x, 2) = tmp(0) '股票名称
If tmp(3) = 0 Then '如果股票代码为空就在下面的行中执行输入“-”
Sheets(1).Cells(idx + x, 3) = "-"
Sheets(1).Cells(idx + x, 4) = "-" '最新价
Sheets(1).Cells(idx + x, 5) = "-" '(最新价-昨收)/昨收
Sheets(1).Cells(idx + x, 6) = "-" '最新价-昨收
Sheets(1).Cells(idx + x, 17) = "-" '涨幅走势
'Sheets(1).Cells(idx + 99, 7) = "-" '最高
'Sheets(1).Cells(idx + 99, 8) = "-" '最低价
' Sheets(1).Cells(idx + 99, 9) = "-" '
' Sheets(1).Cells(idx + 99, 10) = "-" '
'Sheets(1).Cells(2, 6) = idx + x '显示正在运行的行数
Else '如果股票代码 不为空就在下面的行中执行输入数据
Sheets(1).Cells(idx + x, 5) = tmp(3) '最新价
Sheets(1).Cells(idx + x, 4) = (tmp(3) - tmp(2)) / tmp(2) '(最新价-昨收)/昨收=涨跌幅
' Sheets(1).Cells(idx + x, 17) = (tmp(3) - tmp(2)) / tmp(2) - Sheets(1).Cells(idx + x, 17) '涨幅走势
Sheets(1).Cells(idx + x, 6) = tmp(3) - tmp(2) '最新价-昨收=涨跌额
' Sheets(1).Cells(idx + 99, 7) = tmp(4) '最高价
' Sheets(1).Cells(idx + 99, 8) = tmp(5) '最低价
'Sheets(1).Cells(idx + 99, 9) = tmp(15) '换手率
'Sheets(1).Cells(idx + 99, 10) = tmp(24) '量比
Sheets(1).Cells(idx + x, 14) = tmp(8) / 100 '成交(手)
End If
Sheets(1).Cells(idx + x, 16) = tmp(31) '时间
Sheets(1).Cells(2, 6) = idx + x '显示正在运行的行数
Case 18: '源数据是每页18行
Sheets(1).Cells(idx + x, 2) = tmp(1) '股票名称
Sheets(1).Cells(idx + x, 4) = (tmp(6) - tmp(2)) / tmp(2) '(最新价-昨收)/昨收
Sheets(1).Cells(idx + x, 17) = (tmp(6) - tmp(2)) / tmp(2) - Sheets(1).Cells(idx + x, 17) '涨幅走势
Sheets(1).Cells(idx + x, 5) = tmp(6) '最新价
Sheets(1).Cells(idx + x, 6) = tmp(6) - tmp(2) '最新价-昨收=涨跌额
' Sheets(1).Cells(idx + 99, 7) = tmp(4) '最高价
' Sheets(1).Cells(idx + 99, 8) = tmp(5) '最低价
' Sheets(1).Cells(idx + 99, 9) = tmp(15) '换手率
' Sheets(1).Cells(idx + 99, 10) = tmp(24) '量比
Sheets(1).Cells(idx + x, 14) = tmp(8) / 100 '成交(手)
Sheets(1).Cells(idx + x, 16) = tmp(18) '时间
Sheets(1).Cells(2, 6) = idx + x '显示正在运行的行数
Select Case (tmp(6) - tmp(2))
Case Is > 0:
Sheets(1).Range("C" & idx + x & ":F" & idx + x).Font.ColorIndex = 3
Sheets(1).Cells(idx + x, 3) = "↑"
Case 0:
Sheets(1).Range("C" & idx + x & ":F" & idx + x).Font.ColorIndex = 1
Sheets(1).Cells(idx + x, 3) = "-"
Case Is < 0:
Sheets(1).Range("C" & idx + x & ":F" & idx + x).Font.ColorIndex = 4
Sheets(1).Cells(idx + x, 3) = "↓"
End Select
Sheets(1).Cells(2, 6) = idx + x '显示正在运行的行数
End Select
Next
' DoEvents
' Application.OnTime Now + TimeSerial(0, 0, 5), "refresh"
' DoEvents
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
' If Target.Count > 1 Then Exit Sub
' If (Target.Column = 3 Or Target.Column = 4) And Target.Row > 1 Then MsgBox ("ok")
End Sub
Sub 控制程序()
s = Range("h2").Value
s = s + 1
Range("h2").Value = s
Range("D2").Value = "199" '99至324 325空
refresh
Range("D2").Value = "355" ' 99+157=256 257+67=324
refresh
Range("D2").Value = "426" '326至551 552空
refresh
Range("D2").Value = "582" ' 326+157=483 484+67=551
refresh
Range("D2").Value = "653" '553至778 779空
refresh
Range("D2").Value = "809" ' 553+157=710 711+67=778
refresh
Range("D2").Value = "880" '780至1003 1004空
refresh
Range("D2").Value = "1036" ' 780+157=937 938+67=1003
refresh
Range("D2").Value = "1107" '1005至1230 1231空
refresh
Range("D2").Value = "1263" ' 1005+157=1162 1163+67=1230
refresh
Range("D2").Value = "1332" ' 1005+157=1162 1163+67=1230
refresh
Range("D2").Value = "1486" '1005至1230 1231空
refresh
Range("D2").Value = "1553" ' 1005+157=1162 1163+67=1230
refresh
Range("D2").Value = "1710" ' 1005+157=1162 1163+67=1230
refresh
'Range("D2").Value = "1882" ' 1005+157=1162 1163+67=1230
'refresh
' Application.OnTime Now + TimeSerial(0, 0, 5), "控制程序" '每隔5分钟重新运行一次
End Sub |
|