Unique Combo and Pass Value

techissue2008

Board Regular
Joined
Jun 13, 2008
Messages
80
Hi

This thread was I posted:
http://www.mrexcel.com/forum/newreply.php?do=newreply&noquote=1&p=1602161

Code:
Private Sub Worksheet_Activate()
Sheets("Sheet1").Combo1.Clear
 On Error Resume Next
    Dim s As New Collection, arr, rng As Range
    Dim a As Integer
    Dim i As Integer
    a = Sheets("Sheet2").[K65536].End(xlUp).row
    For Each rng In Sheets("Sheet2").Range("K1:K" & K)
        If rng <> "" Then s.Add rng, CStr(rng)
    Next
    ReDim arr(1 To s.Count)
    For i = 1 To s.Count
        arr(i) = s(i)
    Next
    Combo1.List = arr
    Combo1.ListIndex = 0
End Sub

Why the combo cannot show the value and it is empty?

Any advice?
 
I just want to do 2 things:

1) Create a combo drop down menu in sheet 1, non-duplicated and no blank values.

done

2) Pass selected value to another Sub in module when user chooses from drop down menu.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
The item selected from drop down menu is a year, e.g. 2005. Then I want to pass it to another sub's function with IncYear

Code:
Function UniqueSubjects(ws As Worksheet, Subjects() As String, IncYear As Long) As Long
'
' Create list of unique subjects
'
    Dim strName As String
    Dim strLastName As String
    Dim lngRow As Long
    Dim lngNStudents As Long
    Dim colSubjects As Collection
    Dim strSubject As String
   
    Set colSubjects = New Collection
   
    On Error Resume Next
    For lngRow = 1 To ws.Cells(ws.Rows.Count, 3).End(xlUp).row
        If ws.Cells(lngRow, 5) = IncYear Then
             strSubject = UCase(ws.Cells(lngRow, 3))
             colSubjects.Add strSubject, strSubject  'how to sort them? 
        End If
    Next lngRow
  
    ReDim Subjects(1 To colSubjects.Count) As String
    For lngRow = 1 To colSubjects.Count
        Subjects(lngRow) = colSubjects(lngRow)
    Next
    UniqueSubjects = colSubjects.Count
  
End Function

After that, how can I sort the Subjects array by changing to use the following code?

Code:
Sub Sort()
Dim nodupes As New Collection
  With Sheets("Sheet1")
    For Each ce In .Range("A1:B" & .Cells(Rows.Count, 2).End(xlUp).row)
      On Error Resume Next
      nodupes.Add Item:=ce.Value, key:=ce.Value
      On Error GoTo 0
    Next ce
  End With
  
  With Sheets("Sheet2")
    .Cells.ClearContents
    For i = 1 To nodupes.Count
      .Cells(i, "A").Value = nodupes(i)
    Next i
    .Range("A1").Resize(nodupes.Count).Offset(, 1).Formula = "=len(a1)"
    .Range("A1", .Range("A1").End(xlDown)).Resize(, 2).Sort key1:=.Range("B1"), Order1:=xlAscending, Header:=xlNo
    .Columns("b").Delete
End With
End Sub

I am studying sorting with http://www.excelwiki.com/VBA/Arrays-BubbleSort but it seems not similar.
 
Upvote 0
It is sorting on the sheet. (not using BubbleSort at all)
Can you tell me what you are trying to do in WORDS.
Since I used Dictionary object, it will be done at the same time. (much quicker)
 
Upvote 0
Just forget the sorting, it relates to another issue.

I just want to PASS drop down menu "selected value" to a function in another Sub.

e.g. Pass Me.ComboBox1.Selected.value to UniqueSubjects()'s IncYear As Long.
 
Upvote 0
1. The drop down combo works now.
2. It can pass selected value to the function in another Sub too.

both work now, thanks for your help

When I select 2005 in combo in Sheet 1, Sheet 2 will show 2005 student data:

1 2 3
Eng A C D
Math E D C

When I select 2004 in combo in Sheet 1, Sheet 2 still shows 2005 student data.

The data in Sheet 2 cannot be refreshed automatically when user selects a new value from combo.

Do you know how can it be refreshed when user sends new drop down combo selected value to it?
 
Upvote 0
I have no idea at all, because you didn't show us how and when you are calling that function as well as Sort sub.
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,539
Latest member
alex78

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