Solved

Excel Data Validation List Sizing and Selection

Posted on 2015-02-17
10
59 Views
Last Modified: 2015-02-18
Please see attached spreadsheet.

I would like the data validation list show the entire selection - Example: AL - ALABAMA.

But after selection only show the initials - Example after selection form  list :   AL

I also want the column to only be as wide as the selected initials, so selection drop down list is large and shows full selection but column still only as wide as the initials of the state.

Thanks
C--Users-dlehman-Desktop-Test-Sheet.xlsx
0
Comment
  • 6
  • 4
10 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40615144
Add this to sheet1's code.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(ActiveCell, Range("B4:B13")) Is Nothing Then
    Application.EnableEvents = False
    ActiveCell = Left(ActiveCell, 2)
    Columns("B:B").EntireColumn.AutoFit
    Application.EnableEvents = True
End If
End Sub

Open in new window

0
 

Author Comment

by:haradaindustryofamerica
ID: 40615173
Thanks Martin - how to do that?  Sorry for being rookie.
0
 

Author Comment

by:haradaindustryofamerica
ID: 40615195
Thanks MArtin - Been awhile but I remembered.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 40615356
You'll note that the width of the column is being limited by the width of "State" so if you truly want it to be the width of the abbreviation you could change the heading to "ST" or change line 5 to  Columns("B").ColumnWidth = 2.45.


In any case you're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
 

Author Comment

by:haradaindustryofamerica
ID: 40616689
Hi Martin,

I have used the lines in a new sheet (see attached) but for some reason it is not working properly for resizing the column as well as the drop down list.

Could you please take a look at the attached sheet the "Type" column and let me know what I am doing wrong?

Thanks
C--Users-dlehman-Desktop-Part-Order-Form
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40616776
The drop-down list worked for me but it was resizing the wrong column.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(ActiveCell, Range("C12:C21")) Is Nothing Then
    Application.EnableEvents = False
    ActiveCell = Left(ActiveCell, 2)
'    Columns("B:B").EntireColumn.AutoFit
    Columns("C:C").EntireColumn.AutoFit
    
    Application.EnableEvents = True
End If
End Sub

Open in new window

0
 

Author Comment

by:haradaindustryofamerica
ID: 40616860
Martin,

Great thanks, that works perfect now for me before saving the file.

After I save the file and then re-open the file to add more data, the data validation list sizing does not work properly. Please see two screen shot attachments of before and after save.
C--Users-dlehman-Desktop-After-save---Re
C--Users-dlehman-Desktop-Before-Saving-a
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40616991
I think the best solution is to not manipulate the width of the Type column at all but rather just set it to about 17 and keep it static. Other than that I see only two other choices:

1) Add this code to the workbook.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(ActiveCell, Range("C12:C21")) Is Nothing Then
    Target.Columns.ColumnWidth = 15
End If
End Sub

Open in new window

There a small problem with this approach and that is if you select a Type and then try to change the Type without first moving off the cell, the cell won't expand.

2) Use the code in my Magical Floating ActiveX Control article to float a wider combobox on top of the dropdown list. I could help you with that if you want, but I'd appreciate it if you'd open a new question for that.
0
 

Author Comment

by:haradaindustryofamerica
ID: 40617314
Holy mackerel that is way past my experience level, I will open a ticket for your assistance!

Thanks Martin.
0
 

Author Comment

by:haradaindustryofamerica
ID: 40617335
Martin - New question posted.

Question title
  -  Magical Floating ActiveX Control fro Excel Data Validation List
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question