Function CB_IndexCompute0() As Double
Dim i, j, width As Integer
Dim numerator, denominator, denominator_Pre, CB_Index_pre As Double
'Dim c
Dim c As Range
'i Today 中CB的个数
'j 为转债余额表中CB的个数
'numerator为CB总市值
'denomintor为除数
'MsgBox "Cb_Index0000"
i = 0
j = 0
CB_Index_pre = Worksheets("TODAY").Cells(13, 2).Value
denominator_Pre = Worksheets("TODAY").Cells(13, 3).Value For Each c In Worksheets("TODAY").[B2:BZ2]
If c.Value <> "" Then
i = i + 1
End If
Next 'Dim CB_volumebook As String
'CB_volumebook = "D:\Index\转债余额表"
'CB_volumebook为转债余额表的路径
'Application.Workbooks.Open Filename:=CB_volumebook, updatelinks:=3
Workbooks("转债余额表").Activate
For Each c In Worksheets("每日余额").[B2:BZ2]
If c.Value <> "" Then
j = j + 1
End If
Next
If j = i Then
ActiveWorkbook.Close
Workbooks("最新").Worksheets("TODAY").Activate
Dim Today_Volume(), Today_Price(), Yesterday_Volume(), Yesterday_Price() As Double
ReDim Today_Volume(i - 1)
ReDim Today_Price(i - 1)
ReDim Yesterday_Volume(i - 1)
ReDim Yesterday_Price(i - 1) Dim p, q As Integer
For q = 0 To i - 1 Step 1
Today_Volume(q) = Cells(5, q + 2).Value
Today_Price(q) = Cells(8, q + 2).Value
Yesterday_Volume(q) = Cells(6, q + 2).Value
Yesterday_Price(q) = Cells(9, q + 2).Value
Next '判断有无存量的变化
'senario=0,存量没有变化
'senario=1,存量有变化
Dim senario As Integer
'Dim Index_Volume() As Integer p = 0
For q = 0 To i - 1 Step 1
If Today_Volume(q) <> Yesterday_Volume(q) Then
'ReDim Index_Volume(p)
'Index_Volume(p) = q
p = p + 1
End If
Next 'Dim temp() As Double If p <> 0 Then
senario = 1
Else: senario = 0
End If Select Case senario
Case 0
numerator = 0
For q = 0 To i - 1 Step 1
If Today_Volume(q) > 0 Then
numerator = numerator + Today_Volume(q) * Today_Price(q) / 100000000
End If
Next
CB_IndexCompute0 = numerator / denominator_Pre
denominator = denominator_Pre Case 1
Dim numerator_alternative As Double
Dim check As Double
numerator = 0
numerator_alternative = 0
For q = 0 To i - 1 Step 1
numerator = numerator + Yesterday_Volume(i) * Today_Price(i) / 100000000
numerator_alternative = numerator_alternative + Today_Volume(i) * Today_Price(i) / 100000000
Next
denominator = denominator_Pre * numerator_alternative / numerator
CB_IndexCompute0 = numerator / denominator_Pre
check = numerator_alternative / denominator
MsgBox check - CB_IndexCompute0 End Select
'Dim q As Integer
'For q = 1 To i Step 1
'If Cells(5, q).Value > 0 Then
'If Cells(8, i).Value = 0 Then
'Cells(8, i).Value = Cells(9, i).Value
'Cells(8, i).Font.Color = 3 'Compute0_Volume:
'Dim numerator_alternative As Double
'numerator = 0
'numerator_alternative = 0
'For q = 0 To i - 1 Step 1
'numerator = numerator + Yesterday_Volume(i) * Today_Price(i) / 100000000
'numerator_alternative = numerator_alternative + Today_Volume(i) * Today_Price(i) / 100000000
'Next
'denominator = denominator_Pre * numerator_alternative / numerator
'CB_IndexCompute0 = numerator / denominator_Pre
'Dim check As Double
'check = numerator_alternative / denominator
'GoTo Lastline End If End Function
不能返回值 不知道那个地方出错 |