Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Width of drop down in data validation

Hi experts!

I found this great code to temporarily change the width of a column to
overcome problems with the width of the drop down field (for data
validation):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 4 Then
Target.Columns.ColumnWidth = 20
Else
Columns(4).ColumnWidth = 5
End If
End Sub

Checkout: http://www.contextures.com/xlDataVal08.html

PROBLEM: I want to make this code applicable to an entire range of
columns (columns 17-85) and not only to a single one (in this case
column 4). Is there any way to tweak the code? I can change the "If
Target.Column =4 Then" to "If TargetColumn 17 And <85" but then the
code after "Else" will not work.

Thanks for your help.
Rene

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Width of drop down in data validation

Use a public variable at the top of the module to "remember" what column you
last increased the width of.

public col as Range
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
if not col is nothing then
col.EntireColumn.ColumnWidth = 5
set col = nothing
end if
If Target.Count 1 Then Exit Sub
If Target.Column = 17 and Target.Column <= 85 Then
Target.Columns.ColumnWidth = 20
set col = Target.EntireColumn
end if
End Sub



--
Regards,
Tom Ogilvy

"Rene" wrote:

Hi experts!

I found this great code to temporarily change the width of a column to
overcome problems with the width of the drop down field (for data
validation):

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 4 Then
Target.Columns.ColumnWidth = 20
Else
Columns(4).ColumnWidth = 5
End If
End Sub

Checkout: http://www.contextures.com/xlDataVal08.html

PROBLEM: I want to make this code applicable to an entire range of
columns (columns 17-85) and not only to a single one (in this case
column 4). Is there any way to tweak the code? I can change the "If
Target.Column =4 Then" to "If TargetColumn 17 And <85" but then the
code after "Else" will not work.

Thanks for your help.
Rene


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Width of drop down in data validation

Hi Tom!

Thanks for the quick response! Just what I was looking for!

Thank you!
Rene

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation drop-down width, with named range source (XL03 and ker_01 Excel Worksheet Functions 4 March 24th 10 03:31 PM
Data Validation Drop Down Menu Width Zee[_2_] Excel Discussion (Misc queries) 1 November 4th 08 06:42 PM
Drop down list box width - data validation Laura Excel Discussion (Misc queries) 1 March 17th 06 09:58 PM
Data Validation - width of drop down box Laura Excel Discussion (Misc queries) 0 March 16th 06 10:18 PM
A new twist to the validation drop-down width question. Spongebob Excel Discussion (Misc queries) 2 May 26th 05 09:12 PM


All times are GMT +1. The time now is 09:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"