dポイントプレゼントキャンペーン実施中!

早速ですが 変数を 使いたいのですが

endrh = Cells(20000, 1).End(xlUp).Row
 If Target.Address = "$L$" & endrh & "'" Then 
エラーは帰えさないのですが =が動きません <> は反応します。
VB的には こうだと思うのですが、=で 下に入ってくれません

If Target.Address = "$L$" & endrh " Then
構文エラー 

If Target.Address = Cells(12, endrh) Then
オブジェクト定義エラー


ヘルプは
'Application.EnableEvents = False
'If Target.Address = "$K$1" Then
' Range("A1").Value = "X" '(セルの値変更例)
'End If
'イベントを有効にする
'Application.EnableEvents = True

どこに間違いがあるのでしょうか

A 回答 (1件)

Private Sub Worksheet_Change(ByVal Target As Range)


Application.EnableEvents = False
endrh = Cells(20000, "A").End(xlUp).Row
MsgBox endrh
If Target.Address = "$A$" & endrh Then
MsgBox "pass"
' Range("A1").Value = "X" '(セルの値変更例)
End If
'イベントを有効にする
Application.EnableEvents = True
MsgBox Target
End Sub
こういう例ではうまく行くのでは。
ーーー
If Target.Address = "$L$" & endrh " Then
構文エラー 
のendrh のあとの"は要らないのでは?。 <-----原因?

A列以外で察知
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
endrh = Cells(20000, "A").End(xlUp).Row
MsgBox endrh
If Target.Row = endrh Then
MsgBox "pass"
' Range("A1").Value = "X" '(セルの値変更例)
End If
'イベントを有効にする
Application.EnableEvents = True
MsgBox Target
End Sub
Msgbox を沢山挟んで実行して様子を見ることをお奨めする。
    • good
    • 0
この回答へのお礼

サンクス

VB6 と 勝手が違って、
とりあえず、通りました。ありがとうございます

お礼日時:2011/09/11 15:03

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!