NEED HELP WITH MY CODE - GETTING ERROR MESSAGE


Posted by Montgomery on September 24, 2001 3:50 AM

Hello,
I am having a slight problem with my listbox can someone have a look at this code and see why i am having an error.

Could not set list property/Invalid property value

dim seltext as string
dim i as integer
const perilslbx = 1 "perils in column A
seltext = " ' "
with perilslbx
for i = 0 to perils.listcount - 1
if perils.selected(i) then
seltext = perils.list(i) & " "
end if
next i
end with
Cells(65536, perilscol).end(xlup).Offset(1).value=seltext

Thanks for your help



Posted by Damon Ostrander on September 24, 2001 8:57 AM

Hi Montgomery,

There are several apparent problems here:

1) I believe you intended to declare the constant perilscol rather than perilslbx. I assume perilslbx is the name of your listbox.

2) The With statement does not qualifiy anything at present because there is nothing that needs qualification. I believe you meant to use it to qualify all the perilslbx properties, in which case your code should be:

dim seltext as string
dim i as integer
const perilscol = 1 "perils in column A
seltext = " ' "
with perilslbx
for i = 0 to .listcount - 1
if .selected(i) then
seltext = .list(i) & " "
end if
next i
end with
Cells(65536, perilscol).end(xlup).Offset(1).value=seltext

3) Right now seltext will end up set to the last selected item in the listbox. It appears that you might have intended for it to contain all the selected items concatenated together. If this is the case, the line

seltext = .list(i) & " "

should look something like

seltext = seltext & .list(i) & " "

Happy computing.

Damon