Skip to content

Instantly share code, notes, and snippets.

@YujiFukami
Created August 18, 2023 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YujiFukami/ec7f060119b1e996e63cb8e682faec07 to your computer and use it in GitHub Desktop.
Save YujiFukami/ec7f060119b1e996e63cb8e682faec07 to your computer and use it in GitHub Desktop.
Option Explicit
Public Sub SwitchColWidth(Optional ByRef Narrow As Double = 0.6, _
Optional ByRef Wide As Double = 2)
'引数
'Narrow・・・狭いときの列幅
'Wide ・・・広いときの列幅
Dim Sheet As Worksheet: Set Sheet = ActiveSheet
Dim CommnadButton As Shape: Set CommnadButton = Sheet.Shapes(Application.Caller)
Dim StartCell As Range: Set StartCell = CommnadButton.TopLeftCell
Dim EndCell As Range: Set EndCell = CommnadButton.BottomRightCell.Offset(-1, -1)
Dim Condition As String: Condition = StartCell.Value
' If TargetCell.EntireColumn.ColumnWidth = Dbl_狭い幅
If Condition = "狭" Then
Range(StartCell, EndCell).EntireColumn.ColumnWidth = Narrow
StartCell.Value = "広"
Else
Range(StartCell, EndCell).EntireColumn.ColumnWidth = Wide
StartCell.Value = "狭"
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment