|
あー・・非表示にする列の方が、多かったんですね。それも考慮するなら、表示する
項目だけを選択する形にした方が、より能率的ですね。
というわけで書き直してみました。
↓対象シートのシートモジュールへ
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, _
Cancel As Boolean)
Dim Lp As Single, Wp As Single, Hp As Single
Dim C As Range
With Target
If .Count > 1 Then Exit Sub
If .Row > 1 Then Exit Sub
Lp = .Left: Wp = .Width * 2: Hp = .Height
End With
Cancel = True
Columns("B:M").Hidden = False
With ActiveSheet.Buttons.Add(Lp, 0.1, Wp, Hp)
.Caption = "月を選択"
.Font.Size = 9
.OnAction = "Scl_MyM"
End With
With ActiveSheet.ListBoxes.Add(Lp, Hp + 2, Wp, Hp * 8)
For Each C In Range("B1", Range("B1").End(xlToRight))
.AddItem C.Value
Next
.MultiSelect = xlSimple
End With
End Sub
↓標準モジュールへ
Sub Scl_MyM()
Dim i As Integer
If VarType(Application.Caller) <> 8 Then Exit Sub
ActiveSheet.Buttons(1).Delete
With ActiveSheet.ListBoxes(1)
If IsError(Application.Match(True, .Selected, 0)) Then
.Delete: Exit Sub
End If
For i = 1 To .ListCount
If .Selected(i) = False Then
Columns(i + 1).Hidden = True
End If
Next i
.Delete
End With
End Sub
|
|