- 帖子
- 15
- 主題
- 6
- 精華
- 0
- 積分
- 58
- 點名
- 0
- 作業系統
- Windows 7
- 軟體版本
- Office 2010
- 閱讀權限
- 20
- 性別
- 男
- 註冊時間
- 2015-7-31
- 最後登錄
- 2018-5-6
|
[發問] EXCEL VBA 如何將重複的程式合併
本帖最後由 ken2192 於 2018-1-1 20:45 編輯
各位版友好,
以下是我在excel vba中,某一檔股票某條件成立之後,自動在固定儲存格裡累加次數,但excel中會有50檔的股票,於是我只能複製貼上一樣的指立,並修改M9->M10。
但由於太繁瑣且要應用在9-50列,請問版友我如何將重複的指令合併在同一個程式裡,每檔股票成單獨事件自動去累加!!
Private Sub Worksheet_Change(ByVal Target As Range)
Call script1(Target)
Call script2(Target)
Call script3(Target)
Call script4(Target)
End Sub
--------------------------------------------------------------
Private Sub script1(ByVal Target As Range)
If Target.Cells.Address = "$M$9" Then
If [M9] >= [P9] * 0.01 Then
[L9] = [M9] / [M9] + [L9]
End If
End If
End Sub
------------------------------------------------------------------
Private Sub script2(ByVal Target As Range)
If Target.Cells.Address = "$M$10" Then
If [M10] >= [P10] * 0.01 Then
[L10] = [M10] / [M10] + [L10]
End If
End If
End Sub
--------------------------------------------------------------------
Private Sub script3(ByVal Target As Range)
If Target.Cells.Address = "$M$11" Then
If [M11] >= [P11] * 0.01 Then
[L11] = [M11] / [M11] + [L11]
End If
End If
End Sub
---------------------------------------------------------------------
Private Sub script4(ByVal Target As Range)
If Target.Cells.Address = "$M$12" Then
If [M12] >= [P12] * 0.01 Then
[L12] = [M12] / [M12] + [L12]
End If
End If
End Sub |
|