harrysolomon
New Member
- Joined
- Mar 6, 2002
- Messages
- 25
I have a workbook which contains 6 worksheets and in each of those worksheets there are multiple columns which contain Data Validation Dropdown lists.
I want to be able to adjust the width of the dropdown lists when the users click on them so they can see the values to be selected and then when they select a value, I'd like the column to auto adjust it's width to the selected value.
I found some code online which does this great but I can only use the code for a single column, in
the following example it only works on the dropdown list in Column 7.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 7 Then
Target.Columns.ColumnWidth = 20
Else
Columns(7).AutoFit
End If
End Sub
How can I change this so it can be used on other columns? For example, I want it to work on the lists where Target.Column = 3,
or Target.Column = 7 or Target.Column = 8 or Target.Column = 9.
I'm also going to want to use this across all the worksheets in the workbook but I'm guessing that would just be a matter of assigning this code to each worksheet?
Thanks.
I want to be able to adjust the width of the dropdown lists when the users click on them so they can see the values to be selected and then when they select a value, I'd like the column to auto adjust it's width to the selected value.
I found some code online which does this great but I can only use the code for a single column, in
the following example it only works on the dropdown list in Column 7.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 7 Then
Target.Columns.ColumnWidth = 20
Else
Columns(7).AutoFit
End If
End Sub
How can I change this so it can be used on other columns? For example, I want it to work on the lists where Target.Column = 3,
or Target.Column = 7 or Target.Column = 8 or Target.Column = 9.
I'm also going to want to use this across all the worksheets in the workbook but I'm guessing that would just be a matter of assigning this code to each worksheet?
Thanks.