PDA

View Full Version : Solved: Listbox value as input



shunz
05-13-2012, 12:37 AM
Hi,

I am trying to use the values of listbox to search certain items. Below is a portion of my code:

Sub search()


If ActiveSheet.Shapes("ListBox1").Value = "Ahom Kingdom" Then


Range("GR5").Select
ActiveSheet.Shapes("Object 67").Select

End Sub()

All I am trying to do here is that if the value selected in the listbox is "ahom kingdom" , then object 67 should be selected.

The code doesn't work. There is some error in the first line. Please help me rectify it.

Bob Phillips
05-13-2012, 04:27 AM
What sort of listbox is it, forms or ActiveX? Where is the listbox sourced from?

shunz
05-13-2012, 04:53 AM
ActiveX.

It is sourced from a cell range available in the same sheet. I entered the range in ListFillRange ( right-click ListBox--->Properties-->ListFillRange)

shunz
05-13-2012, 09:54 PM
I was able to find an alternative:


Sub search()

Select Case outline.Listbox1.Value

Case "Ahom Kingdom"


Range("GR5").Select
ActiveSheet.Shapes("Object 67").Select

End Select

End Sub()
looks like listbox.value doesnt work with IF statement

Bob Phillips
05-14-2012, 12:20 AM
Sure you can

If ActiveSheet.OLEObjects("ListBox1").Object.Value = "Ahom Kingdom" Then

Range("GR5").Select
ActiveSheet.Shapes("Object 67").Select
End If

shunz
05-14-2012, 07:50 AM
thank you. that worked :).