[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『シートモジュール』(ララダス)
Excel2002.WindowsXP使用
こちらの過去ログを参考に↓のコードを作りました。
同じマクロをsheet(1)〜sheet(13)に適用したいのですが、全てのシートにコードを記述する以外に方法は無いのでしょうか?
見ての通り、セル上で右クリックしたら"○"を表示すると言う物です。
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Row < 4 Then Exit Sub
If Target.Row > 34 Then Exit Sub
If Target.Column > 8 Then Exit Sub
If Target.Column < 5 Then Exit Sub
Cancel = True
If Target.Value = "○" Then
Target.Value = ""
Else
Target.Value = "○"
End If
End Sub
よろしくお願いします。
(ララダス)
ThisWorkBookモジュールに書き込みます。
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If Target.Row < 4 Then Exit Sub
If Target.Row > 34 Then Exit Sub
If Target.Column > 8 Then Exit Sub
If Target.Column < 5 Then Exit Sub
Select Case ActiveSheet.Index
Case 1 To 13
Cancel = True
If Target.Value = "○" Then
Target.Value = ""
Else
Target.Value = "○"
End If
End Select
End Sub
順番としては、どちらが良いのだろう・・・。
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Select Case ActiveSheet.Index
Case 1 To 2
If Target.Row < 4 Then Exit Sub
If Target.Row > 34 Then Exit Sub
If Target.Column > 8 Then Exit Sub
If Target.Column < 5 Then Exit Sub
Cancel = True
If Target.Value = "○" Then
Target.Value = ""
Else
Target.Value = "○"
End If
End Select
End Sub
(川野鮎太郎)
こんな感じでよいのでは?
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
If Sh.Index > 13 Then Exit Sub
If Intersect(Target,Sh.Range("e4:g34")) Is Nothing Then Exit Sub
With Target
Cancel = True
If .Value = "○" Then
.Value = ""
Else
.Value = "○"
End If
End With
(seiya)
んだば、σ(^o^;)もw
Private Sub Workbook_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim x As Range
If Sh.Index > 13 Then Exit Sub
For Each x In Target
If Not Intersect(x, Sh.Range("E4:G34")) Is Nothing Then
With x
Cancel = True
If .Value = "○" Then
.Value = ""
Else
.Value = "○"
End If
End With
End If
Next x
End Sub
(キリキ)(〃⌒o⌒)b
出来ました。(^o^) 川野鮎太郎さん・seiyaさん・キリキさんありがとうございました。
一番シンプルなseiyaさんのコードを使わせて頂きました。 それにしても色々な記述のしかたがあるものですね。
Ps.川野鮎太郎さん、印刷マクロの節はお世話になりました。
(ララダス)
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.