我的想法是用
Private Sub Worksheet_Change(ByVal Target As Range)
End Sub
但是不知道可不可以只針對該worksheet中的某個儲存格?
然後再設定一個public變數,每當儲存格變動時,x=x+1,最後回傳x
另外想再請教:
在abc()中call def(x,y)
sub def(x as integer,y as integer)
end sub
出現ByRef引數型態不符,該如何解決?
感謝作者: GBKEE 時間: 2010-10-26 13:33
回復 1#mnsmrtl http://forum.twbts.com/thread-1714-1-1.html
Private Sub Worksheet_Change(ByVal Target As Range)
Static x
If Target.Address="$A$1" Then X=X+1
End Sub
****************
Sub abc()
def x ,y
end sub作者: mnsmrtl 時間: 2010-10-27 11:55
感謝版主幫忙,但第二個問題還是出現同樣結果
程式碼如下:
Sub strike()
Dim i, j, k, l
i = Round(Sheet3.Cells(2, "F") / 50, 0) * 50
j = i Mod 100
k = IIf(j = 0, i, (Int(i / 100) + 1) * 100)
l = IIf(j = 0, i, Int(i / 100) * 100)
strikein k, l
End Sub
Sub strikein(x As Single, y As Single)
Sheet3.Cells(4, "M") = x
Sheet3.Cells(4, "N") = y
End Sub
其中k和l是有小數點的,所以應該是用single…吧?
錯誤訊息仍然是引數型態不符,再次感謝版主幫忙作者: mnsmrtl 時間: 2010-10-27 13:04
另外想再請教,如果要把x輸出到cells(14,14)
我是這樣寫的
Private Sub Worksheet_Change(ByVal Target As Range)
Static x As Integer
If Target.Address = "H2" Then x = x + 1
Cells(14, 14) = x
End Sub
不過似乎行不通作者: GBKEE 時間: 2010-10-27 13:56
回復 3#mnsmrtl
變數型態需相同
Sub strike()
Dim i, j, k As Single, l As Single
i = Round(Sheet3.Cells(2, "F") / 50, 0) * 50
j = i Mod 100
k = IIf(j = 0, i, (Int(i / 100) + 1) * 100)
l = IIf(j = 0, i, Int(i / 100) * 100)
strikein k, l
End Sub
''''''''''''''''''''''''''''''
或是給直接計算值
Sub strike()
Dim i, j
i = Round(Sheet3.Cells(2, "F") / 50, 0) * 50
j = i Mod 100
strikein IIf(j = 0, i, (Int(i / 100) + 1) * 100), IIf(j = 0, i, Int(i / 100) * 100)
End Sub
回復 4#
請詳看VBA的 Address 說明
If Target.Address = "$H$2" Then
或是
If Target.Address(0, 0) = "H2" Then作者: mnsmrtl 時間: 2010-10-28 09:53