Solved

VBA adding a DropDown over a cell that flexes with it

Posted on 2012-03-17
2
225 Views
Last Modified: 2012-03-17
Hi. I was given the VBA code below to add a DropDown to a cell. How do I modify it so that it fits into the cell and what code would I add so that if the user changes the cells size the DropDown automatically changes too

With ActiveSheet.DropDowns.Add(142.5, 38.25, 108.75, 24)
    .Top = Range("C1").Top
    .Left = Range("C1").Left
End With
0
Comment
Question by:murbro
2 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 37732332
Add this to the sheet module

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With ActiveSheet.DropDowns.Add(142.5, 38.25, 108.75, 24)
    .Top = Range("C1").Top
    .Left = Range("C1").Left
    .height= Range("C1").height
    .width= Range("C1").width
End With
End Sub

Open in new window


This will be triggered every the cursor is moved on the sheet but not when the cell height or width is modifies.
0
 

Author Closing Comment

by:murbro
ID: 37733252
Thanks very much
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

919 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now