Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 516
Default Excel Script for Drop Down Menu

i some kind person gave me the code below to insert into my spreadsheet to
remove the white space from my drop down menus. the issue is that i have 15
of these on the same page. can i just copy and
paste the same codes below the first (changing names and fields of course),
or do i need to make a new module? Please advise.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim t, List
For t = 18 To 24
If Cells(t, "H") < "" Then List = List & "," & Cells(t, "H")
Next
With Range("H2").Validation
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With
End Sub


Matt


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Excel Script for Drop Down Menu

You cannot have more than one SelectionChange event in that sheet.

You need to process ad serium

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim t, List
For t = 18 To 24
If Cells(t, "H") < "" Then List = List & "," & Cells(t, "H")
Next
With Range("H2").Validation
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With
With Range("H2").Validation '<=== change H4 to the real cell
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With

'etc.

End Sub

or you could a utility proc


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim t, List
For t = 18 To 24
If Cells(t, "H") < "" Then List = List & "," & Cells(t, "H")
Next

Call SetupDV(Me.Range("H2")
Call SetupDV(Me.Range("H4")
'etc.

End Sub

Private Sub SetupDV(rng As Range)
With rng.Validation
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Matt" wrote in message
...
i some kind person gave me the code below to insert into my spreadsheet to
remove the white space from my drop down menus. the issue is that i have
15
of these on the same page. can i just copy and
paste the same codes below the first (changing names and fields of
course),
or do i need to make a new module? Please advise.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim t, List
For t = 18 To 24
If Cells(t, "H") < "" Then List = List & "," & Cells(t, "H")
Next
With Range("H2").Validation
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With
End Sub


Matt




  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 516
Default Excel Script for Drop Down Menu

I don't think either of those things will work because each drop down list
pulls data from a different place. i only have 1 year of C++ as programming
experience and i feel like the solution is possible, but i don't know enough
VB to figure it out. Please help.

"Bob Phillips" wrote:

You cannot have more than one SelectionChange event in that sheet.

You need to process ad serium

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim t, List
For t = 18 To 24
If Cells(t, "H") < "" Then List = List & "," & Cells(t, "H")
Next
With Range("H2").Validation
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With
With Range("H2").Validation '<=== change H4 to the real cell
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With

'etc.

End Sub

or you could a utility proc


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim t, List
For t = 18 To 24
If Cells(t, "H") < "" Then List = List & "," & Cells(t, "H")
Next

Call SetupDV(Me.Range("H2")
Call SetupDV(Me.Range("H4")
'etc.

End Sub

Private Sub SetupDV(rng As Range)
With rng.Validation
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Matt" wrote in message
...
i some kind person gave me the code below to insert into my spreadsheet to
remove the white space from my drop down menus. the issue is that i have
15
of these on the same page. can i just copy and
paste the same codes below the first (changing names and fields of
course),
or do i need to make a new module? Please advise.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim t, List
For t = 18 To 24
If Cells(t, "H") < "" Then List = List & "," & Cells(t, "H")
Next
With Range("H2").Validation
.Delete
.Add xlValidateList, Formula1:=List
.InCellDropdown = True
End With
End Sub


Matt





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
how do you creat a drop down menu in excel? Excel hell Excel Discussion (Misc queries) 1 May 20th 06 04:59 PM
Cross-referenced drop-down menu (nested drop-downs?) creativeops Excel Worksheet Functions 4 November 22nd 05 05:41 PM
Check box and a drop down menu in Excel EMarin Excel Discussion (Misc queries) 1 April 12th 05 01:23 AM
How do u insert a drop down menu in a Excel Guru Excel Worksheet Functions 1 January 28th 05 05:45 PM
how do i create drop down menu in excel ezeflier Excel Worksheet Functions 2 November 5th 04 02:39 PM


All times are GMT +1. The time now is 08:13 AM.

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"