Forum Discussion

DJ_Excel's avatar
DJ_Excel
Copper Contributor
Aug 06, 2021
Solved

Run macro if columns in a specific line are selected

Hi, I barelly remeber how to write VBA so i tend to find scripts on the internet. I found one that i wanted to modify but i cant seem to make the correct changes.   Essentially i want to add a co...
  • HansVogelaar's avatar
    HansVogelaar
    Aug 06, 2021

    DJ_Excel 

    I see. Here is a new version:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Range("H1:AB1").ColumnWidth = 15
        If Target.Count > 1 Then Exit Sub
        If Target.Row <> 65 Then Exit Sub
        If Target.Column >= 8 And Target.Column <= 28 Then
            Target.ColumnWidth = 50
        End If
    End Sub

Resources