populate multicolumn listbox?

A

Alen32

I got thics code here but I can't insert results in listbox.

With userform1
if .optionButton1 then
sOne = "Horse"
else
sOne = "Pig"
end if
if .optionButton3 then
sTwo = "Danish"
else
sTwo = "Foreign"
end if
sThree = .Textbox1.Text
End With
With Worksheets(1).Cells
Set c = .Find(sOne, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
if application.countif(c.EntireRow,"*" & sTwo & "*") and _
application.Countif(c.EntireRow,"*" & sThree & "*") then
' add row to listbox
end if
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
 
T

Tom Ogilvy

You just said you wanted to add the row to the listbox. That is
significantly vague. Obviously you don't want to add 256 cells to the
listbox. so what do you want to do? What cells in the found code do you
want to add to the listbox.
 
A

Alen32

like her:
.ListBox1.AddItem cell.Value
.ListBox1.List(.ListBox1.ListCount - 1, 1) _
= cell.Offset(0, 2).Value
.ListBox1.List(.ListBox1.ListCount - 1, 2) _
= cell.Offset(0, 5).Value
 
T

Tom Ogilvy

With userform1
if .optionButton1 then
sOne = "Horse"
else
sOne = "Pig"
end if
if .optionButton3 then
sTwo = "Danish"
else
sTwo = "Foreign"
end if
sThree = .Textbox1.Text
End With
With Worksheets(1).Cells
Set c = .Find(sOne, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
if application.countif(c.EntireRow,"*" & sTwo & "*") and _
application.Countif(c.EntireRow,"*" & sThree & "*") then
Userform1.ListBox1.AddItem c.Value
Userform1.ListBox1.List( _
Userform1.ListBox1.ListCount - 1, 1) _
= c.Offset(0, 2).Value
Userform1.ListBox1.List( _
Userform1.ListBox1.ListCount - 1, 2) _
= c.Offset(0, 5).Value
end if
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With

Assuming the cell you want to base your offset on is the the one containing
pig or horse
 

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

Similar Threads


Top