我寫了一個輸入文字就會帶出時間的程式 如下 這個程式在B行打出後就會顯現出時間 但是很奇怪...我想把B行改成其他行 我把[B65536]改成[C65536]或[D65536] 就跑不出來了...... 想請問是什麼原因呢? 如果要改到其他行正確的改法要怎麼改呢?

2017-09-01 5:06 pm
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Lst As Integer, r As Integer
Lst = [B65536].End(xlUp).Row


If Target.Count > 2 Then Exit Sub
r = Target.Row
If r > Lst Then Exit Sub


If Target.Column <> 2 Then Exit Sub


If Target = "" Then
Target.Offset(0, 4) = ""

Else
Target.Offset(0, 4) = Date & Time

End If



End Sub
更新1:

這個是VBA

回答 (2)

2017-09-02 7:57 am
✔ 最佳答案
試吓咁

Dim Lst As Integer, r As Integer
Dim currentColumnNum As Integer
Dim offsetColumnNum As Integer

Lst = [C65536].End(xlUp).Row
currentColumnNum = ActiveCell.Column
offsetColumnNum = 3 ' Date & Time 如果改為D column這行須要更改為 2

If Target.Count > 2 Then Exit Sub
r = Target.Row
If r > Lst Then Exit Sub

If Target.Column <> currentColumnNum Then Exit Sub

If Target = "" Then
Target.Offset(0, offsetColumnNum) = ""
Else
Target.Offset(0, offsetColumnNum) = Date & Time
End If

End If
2017-09-02 1:52 pm
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 2 Then ''指定B欄
If Target > "" Then
Target.Offset(0, 4) = Date & Time
Else
Target.Offset(0, 4) = ""
End If
End If
End Sub


收錄日期: 2021-05-03 06:47:21
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20170901090633AA0iXmk

檢視 Wayback Machine 備份