setting "width" list box in data validation list

iwans

New Member
Joined
May 11, 2004
Messages
7
dear....can i set width in list box data validation (width in cell i set short).thanks

width.gif
 
Re: setting "width" list box in data validation li

Hi - I found this code below and it works well - the only snag is that whenever I save the file it stops working (I'm using it embedded within an event) - the save method seems to cause the code to permanently lose the shape instance (although I can get it back by closing out of the file and then re-opening).

Any ideas as to how I might overcome this problem???

Thanks,
Andy




Hi, the following code courtesy of a previous post by NateO should do it. Substitute A1:A5 for the cells that have drop down data validation boxes & C:C for the cells that have your list. Right click the sheet, select view code and paste the code in the right hand window.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
Dim myShp As Shape, Drp As Single 

On Error Resume Next 

'cells holding drop downs 
If Intersect(Target, [A1:A5]) Is Nothing Then Exit Sub 
If Target.Validation.Type = xlValidateList Then 
    Set myShp = ActiveSheet.Shapes("Drop Down 1") 
    Drp = myShp.Width - Target.Width 

'Column holding list, sized appropriately 
    myShp.Width = [C:C].Width 
    myShp.Left = Target.Left - myShp.Width / 2 + Drp * 2 
End If 

Set myShp = Nothing 

End Sub
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Forum statistics

Threads
1,215,008
Messages
6,122,672
Members
449,091
Latest member
peppernaut

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