Excel VBA Macro not working

mcl48236

New Member
Joined
Jul 7, 2016
Messages
4
Hi All, I am not the best at VBA but am trying to get my macro to work. I have created a combobox drop down list in the developer tab. I want to be able to get the data selected in the combo box into another cell in my workbook, however I am having issues. This is what I have come up with so far

Option Explicit


Sub FilterUniqueData()
Dim Lrow As Long, test As New Collection
Dim Value As Variant, temp() As Variant
ReDim temp(0)

On Error Resume Next
With Worksheets("Sheet1")
Lrow = .Range("A" & Rows.Count).End(xlUp).Row
temp = .Range("A2:A" & Lrow).Value
End With

For Each Value In temp
If Len(Value) > 0 Then test.Add Value, CStr(Value)
Next Value

ReDim temp(0)
Worksheets("Sheet1").Shapes("Drop Down 5").ControlFormat.RemoveAllItems

For Each Value In test
Worksheets("Sheet1").Shapes("Drop Down 5").ControlFormat.AddItem Value
Next Value

Set test = Nothing


End Sub


Sub SelectedValue()
With Worksheets("Sheet1").Shapes("Drop Down 5").ControlFormat
Worksheets("Sheet1").Range("C35") = .List(.Value)
End With
End Sub


but when I go run the macro the cell only populates when I got back into VBA and continue running the selected value part of the code.

Any insights into this would be greatly appreciated!
 
Thank you Norie and Michael for highlighting the issue of the asterisks and thank you Peter for your explanation. Everyday, we learn something.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Thank you Norie and Michael for highlighting the issue of the asterisks and thank you Peter for your explanation. Everyday, we learn something.

Sorry for the multiple back and forth I am a serious new-bee to VBA. Now I keep getting an error that the variable is not defined in red below

Option Explicit

Sub ComboBox5_DropButt*******()
Dim Lrow As Long, test As New Collection
Dim Value As Variant, temp() As Variant
ReDim temp(0)




On Error Resume Next
With Worksheets("Sheet1")
Lrow = .Range("A" & Rows.Count).End(xlUp).Row
temp = .Range("A2:A" & Lrow).Value
End With




For Each Value In temp
If Len(Value) > 0 Then test.Add Value, CStr(Value)
Next Value




ComboBox5.Clear
For Each Value In test
ComboBox5.AddItem Value
Next Value




Set test = Nothing




End Sub




Sub ComboBox5_Click()
Worksheets("Sheet1").Range("C35") = ComboBox5.Text
End Sub
 
Upvote 0
Change the

Sub ComboBox5_Click()

to

Sub ComboBox5_D r o p B u t t o n C l i c k ()

Delete spaces between letters of the above blue word. It should work.
 
Upvote 0
Change the

Sub ComboBox5_Click()

to

Sub ComboBox5_D r o p B u t t o n C l i c k ()

Delete spaces between letters of the above blue word. It should work.


I did that and now I'm get an error that says ambiguous name detected
 
Upvote 0
If we stick with the original code from post #1 have you assigned any macro to the combobox?

Also, how are you running the code to populate the combobox?
 
Upvote 0

Forum statistics

Threads
1,216,737
Messages
6,132,436
Members
449,727
Latest member
Aby2024

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