Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have some code which when a user double clicks on certain cells will
add a dropdown. The code is supposed to add the dropdown so its dimensions match that of the target cell. While the actual dropdowns have the correct length and width, and are placed correctly horizontally, they are always off Vertically. Any ideas? Sub adddropdown(Target As Range, typer As Integer) Dim ddbox As DropDown Dim vaproducts As Variant Dim i As Integer Dim skilllevel As Variant Dim shift As Variant shift = Array("1-Night", "2-Day", "3-Evening") skilllevel = Array("RN", "LVN", "NA", "Other", "Traveler") vaproducts = Array("Maternity Leave", "Workman's Comp", "Family Leave", "Medical Leave", "Other") c = Target.Address 'I HAVE CHECKED THE TARGET ADDRESS AND IT IS THE CORRECT CELL 'BUT THIS NEXT CODE WHERE IT ADDS THE DROPDOWN PUTS IT IN 'THE WRONG SPOT With Target Set ddbox = ActiveSheet.DropDowns.Add (.Left, .Top, .Width, .Height) End With With ddbox ..OnAction = "Enterlet" Select Case typer Case 1 For i = LBound(vaproducts) To UBound(vaproducts) .AddItem vaproducts(i) Next i Case 2 For i = LBound(skilllevel) To UBound(skilllevel) .AddItem skilllevel(i) Next i Case 3 For i = LBound(shift) To UBound(shift) .AddItem shift(i) Next i End Select End With End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub ABCD()
Dim rng As Range Set rng = Range("B9") adddropdown rng, 2 End Sub Sub adddropdown(Target As Range, typer As Integer) Dim ddbox As DropDown Dim vaproducts As Variant Dim i As Integer Dim skilllevel As Variant Dim shift As Variant shift = Array("1-Night", "2-Day", "3-Evening") skilllevel = Array("RN", "LVN", "NA", "Other", "Traveler") vaproducts = Array("Maternity Leave", _ "Workman's Comp", "Family Leave", _ "Medical Leave", "Other") c = Target.Address 'I HAVE CHECKED THE TARGET ADDRESS AND IT IS THE CORRECT CELL 'BUT THIS NEXT CODE WHERE IT ADDS THE DROPDOWN PUTS IT IN 'THE WRONG SPOT With Target Set ddbox = ActiveSheet.DropDowns.Add(.Left, .Top, .Width, .Height) End With With ddbox ..OnAction = "Enterlet" Select Case typer Case 1 For i = LBound(vaproducts) To UBound(vaproducts) .AddItem vaproducts(i) Next i Case 2 For i = LBound(skilllevel) To UBound(skilllevel) .AddItem skilllevel(i) Next i Case 3 For i = LBound(shift) To UBound(shift) .AddItem shift(i) Next i End Select End With End Sub worked fine for me. It must be that your passing the wrong range into the function. -- Regards, Tom Ogilvy "Chip" wrote in message oups.com... I have some code which when a user double clicks on certain cells will add a dropdown. The code is supposed to add the dropdown so its dimensions match that of the target cell. While the actual dropdowns have the correct length and width, and are placed correctly horizontally, they are always off Vertically. Any ideas? Sub adddropdown(Target As Range, typer As Integer) Dim ddbox As DropDown Dim vaproducts As Variant Dim i As Integer Dim skilllevel As Variant Dim shift As Variant shift = Array("1-Night", "2-Day", "3-Evening") skilllevel = Array("RN", "LVN", "NA", "Other", "Traveler") vaproducts = Array("Maternity Leave", "Workman's Comp", "Family Leave", "Medical Leave", "Other") c = Target.Address 'I HAVE CHECKED THE TARGET ADDRESS AND IT IS THE CORRECT CELL 'BUT THIS NEXT CODE WHERE IT ADDS THE DROPDOWN PUTS IT IN 'THE WRONG SPOT With Target Set ddbox = ActiveSheet.DropDowns.Add (.Left, .Top, .Width, .Height) End With With ddbox .OnAction = "Enterlet" Select Case typer Case 1 For i = LBound(vaproducts) To UBound(vaproducts) .AddItem vaproducts(i) Next i Case 2 For i = LBound(skilllevel) To UBound(skilllevel) .AddItem skilllevel(i) Next i Case 3 For i = LBound(shift) To UBound(shift) .AddItem shift(i) Next i End Select End With End Sub |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
A long time ago, someone posted a similar problem--it really raised its ugly
head when the zoom factor wasn't at 100% (smaller, IIRC). I wrote this macro that went into a loop and adjusted the location until it was entirely in the cell. (Pretty ugly!) Tom Ogilvy just set the position a second time and it worked fine. (DOH!). maybe that would work for you: With Target Set ddbox = ActiveSheet.DropDowns.Add(.Left, .Top, .Width, .Height) ddbox.Top = .Top ddbox.Left = .Left ddbox.Width = .Width ddbox.Height = .Height End With Chip wrote: I have some code which when a user double clicks on certain cells will add a dropdown. The code is supposed to add the dropdown so its dimensions match that of the target cell. While the actual dropdowns have the correct length and width, and are placed correctly horizontally, they are always off Vertically. Any ideas? Sub adddropdown(Target As Range, typer As Integer) Dim ddbox As DropDown Dim vaproducts As Variant Dim i As Integer Dim skilllevel As Variant Dim shift As Variant shift = Array("1-Night", "2-Day", "3-Evening") skilllevel = Array("RN", "LVN", "NA", "Other", "Traveler") vaproducts = Array("Maternity Leave", "Workman's Comp", "Family Leave", "Medical Leave", "Other") c = Target.Address 'I HAVE CHECKED THE TARGET ADDRESS AND IT IS THE CORRECT CELL 'BUT THIS NEXT CODE WHERE IT ADDS THE DROPDOWN PUTS IT IN 'THE WRONG SPOT With Target Set ddbox = ActiveSheet.DropDowns.Add (.Left, .Top, .Width, .Height) End With With ddbox .OnAction = "Enterlet" Select Case typer Case 1 For i = LBound(vaproducts) To UBound(vaproducts) .AddItem vaproducts(i) Next i Case 2 For i = LBound(skilllevel) To UBound(skilllevel) .AddItem skilllevel(i) Next i Case 3 For i = LBound(shift) To UBound(shift) .AddItem shift(i) Next i End Select End With End Sub -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Dave. That worked perfectly for me. I don't know why that
works, but I'll take it. Yea it's odd Tom because it definitely doesn't work for me as is, but with Dave's code (setting the position a second time it worked perfectly). Thank you both for the help. This forum wouldnt be where it is without you both. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Your code worked for me as-is.
(just to muddy the waters) Chip wrote: Thanks Dave. That worked perfectly for me. I don't know why that works, but I'll take it. Yea it's odd Tom because it definitely doesn't work for me as is, but with Dave's code (setting the position a second time it worked perfectly). Thank you both for the help. This forum wouldnt be where it is without you both. -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
select From dropdown and return another dropdown menu | Excel Discussion (Misc queries) | |||
Dropdown box display only data dependent on another dropdown box? | Excel Worksheet Functions | |||
offer dropdown options based on another dropdown | Excel Discussion (Misc queries) | |||
MS Bug? Data validation list dropdown with Worksheet_Change event | Excel Programming | |||
OnTime event not firing in Workbook_Open event procedure | Excel Programming |