プロが教える店舗&オフィスのセキュリティ対策術

勤務表作成してます。
A1に「ON・OFF」を表示します。
「ON」のときに、ダブルクリックで、上のセルを表示、右クリックで「1」を表示します。
「OFF」のときは、コンテキストメニュ-(通常の操作)が出来るようにしたいのですが、ON.OFFの切り替え操作のVBAがわかりません。
よろしくお願いします。
Option Explicit

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

' ActiveCell = ActiveCell.Offset(-1, 0).Value
'
' If Target = Range("$A$1") Then
' Cancel = True

If Range("$A$1").Value = "イベントON" Then
Range("$A$1").Value = "イベントOFF"
Else
Range("$A$1").Value = "イベントON"
ActiveCell = ActiveCell.Offset(-1, 0).Value
Exit Sub
End If

Cancel = True
If Range("$A$1").Value = "イベントOFF" Then
Exit Sub
End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

'ActiveCell = "1"
' If Target = Range("$A$1") Then
' Cancel = True

' If Range("$A$1").Value = "イベントON" Then
' Range("$A$1").Value = "イベントOFF"
If Range("$A$1").Value = "イベントON" Then
ActiveCell = "1"

Else: Range("$A$1").Value = "イベントOFF"
Exit Sub
End If
Cancel = True

If Range("$A$1").Value = "イベントOFF" Then
Exit Sub
End If
End Sub

A 回答 (1件)

ON.OFFの切り替えが知りたいの?



http://qanda.rakuten.ne.jp/qa4948485.html
の、方は締め切った方がいいと思うよ
良く見れば違うけど、質問部分は同じだし
「マルチポスト」になると思う

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = "$A$1" Then
Select Case Target.Value
Case "イベントON"
Target.Value = "イベントOFF"
Case "イベントOFF"
Target.Value = "イベントON"
End Select
Cancel = True
Exit Sub
End If
End Sub

Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Address = "$A$1" Then
Select Case Target.Value
Case "イベントON"
Target.Value = "イベントOFF"
Case "イベントOFF"
Target.Value = "イベントON"
End Select
Cancel = True
Exit Sub
End If
End Sub
    • good
    • 0
この回答へのお礼

hige_082様
先ほど、ON,OFFの切り替えができないと、返事いたしましたが、
イベントを入力忘れていました。
希望どおりに出来ました。
いつもありがとうございます。
また、よろしくお願いします。
同質問も注意します。

お礼日時:2009/05/11 20:08

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