Sub 收益率()
Dim a As Integer, b As Integer, 成功筆數 As Integer, 失敗筆數 As Integer, 買入 As Long, 賣出等 As Long, 結算金額 As Long, 交易筆數 As Integer, temp As Long, temp2 As Long
a = Cells(65536, 4).End(xlUp).Row
For b = 2 To a
temp = Cells(b, 4).Value
temp2 = Cells(b, 7).Value
結算金額 = 結算金額 + temp2
If Cells(b, 3).Text = "買入" Then
買入 = 買入 + temp
Else
賣出等 = 賣出等 + temp
End If
If 買入 - 賣出等 = 0 Then
If 結算金額 > 0 Then
成功筆數 = 成功筆數 + 1
Else
失敗筆數 = 失敗筆數 + 1
End If
買入 = 0
賣出等 = 0
結算金額 = 0
End If
Next
交易筆數 = 成功筆數 + 失敗筆數
Cells(2, 11) = 成功筆數
Cells(3, 11) = 失敗筆數
Cells(4, 11) = 交易筆數
End Sub