Why Am I Getting This Error Message Please?

G

Guest

I can't figure out why I'm getting an "invalid qualifier" error message on
this; each time it points to the word 'Selected' in the code. Any help would
be appreciated. (All I want the code to do is: If an item is selected in
Option2ListBox, then I want to delete any row in the Schedules tab that has
that item in Col H.)

Private Sub OKButton_Click()
Dim x As Integer
Dim Lrow As Long

'Loop through the items in the ListBox control.
For x = 0 To Option2ListBox.ListCount - 1

' If the item is selected, then deletes any row in the 'Schedules' tab that
has that value in it
If Option2ListBox.Selected(x) = True Then
If worksheets("Schedules").cells(Lrow, "H").Value =
ImportingSchedules.Option2ListBox.Selected(x).Value Then
worksheets("Schedules").Rows(Lrow).Delete
End If
End If

Next x

Unload ImportingSchedules
End Sub
 
G

George Nicholson

I'm thinking
...ImportingSchedules.Option2ListBox.Selected(x).Value...
should use something other than Selected. maybe:
.....ImportingSchedules.Option2ListBox.List(x,0)...

HTH,
 
D

Don

I'm thinking> ...ImportingSchedules.Option2ListBox.Selected(x).Value...

should use something other than Selected. maybe:
....ImportingSchedules.Option2ListBox.List(x,0)...

HTH,











- Show quoted text -

You need to tell the macro to select the option2ListBox and then check
the value of the selection
I'm not sure what the selection is when the button is clicked, but you
should put that into memory before you select the list box to check
the value so you can re-select what was originally selected.

For example If a range was selected:
Dim ac as range, sel as selection
Set ac = activecell
Set sel = selection

activesheet.shapes("option2ListBox").select
If selection.value = true then
'Insert Code here
end If

sel.select
ac.activate
 
G

Guest

Thanks, guys! Will try these. Don, now that you explain it that way....it
makes more sense. Will work on this and post back the results (for future
reference by others). Appreciate it!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top