以下是我工作表(1)的程式碼,請問OptionButton & i_Click可以寫成迴圈嗎?
還是說每新增一筆選項按鈕的資料,就得新增一次程序?
(如果有1000筆資料,就要Sub 1000次?)
Private Sub OptionButton1_Click()
If OptionButton1 = True Then Cells(1, 2).value = Cells(4, 2)
End Sub
Private Sub OptionButton2_Click()
If OptionButton2 = True Then Cells(1, 2).value = Cells(5, 2)
End Sub
Private Sub OptionButton3_Click()
If OptionButton3 = True Then Cells(1, 2).value = Cells(6, 2)
End Sub
Private Sub OptionButton4_Click()
If OptionButton4 = True Then Cells(1, 2).value = Cells(7, 2)
End Sub
Private Sub OptionButton5_Click()
If OptionButton5 = True Then Cells(1, 2).value = Cells(8, 2)
End Sub 作者: oobird 時間: 2010-8-15 23:08
Sub yy()
Dim o As OLEObject, c%
For Each o In Me.OLEObjects
If o.Name Like "OptionButton" & "*" Then
If o.Object.Value = True Then
c = Replace(o.Name, "OptionButton", "")
Cells(1, 2).Value = Cells(c, 2): Exit For
End If
End If
Next
End Sub
這樣就是迴圈,但你必須執行這個程式而不是點擊OptionButton後自動執行!作者: solely 時間: 2010-8-16 22:05