Change the Size of the Drop down list width with VBA

stathis1234

New Member
Joined
Jun 29, 2018
Messages
7
I have an excel sheet that 6 columns have data validation, (drop down list), i want the width of the drop down list to expand when is selected
the following VBa code worked for me but is only for one column is there any way to do it for 6 columns
the VBA code is the following
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Count > 1 Then Exit Sub

If Target.Column = 1 Then

Target.Columns.ColumnWidth = 30

Else

Columns(1).ColumnWidth = 5

End If

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Which columns do you want it to work on?
 
Upvote 0
See how this goes.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Application.ScreenUpdating = False
  Columns("G:L").ColumnWidth = 5
  If Not Intersect(ActiveCell, Columns("G:L")) Is Nothing Then ActiveCell.ColumnWidth = 30
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Glad it helped. Thanks for the confirmation. :)
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top