View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Alen32 Alen32 is offline
external usenet poster
 
Posts: 78
Default option button-if else?

sorry I have difuculties to explain in english what I want. I got this code
here which works well. Now I want to make third optionbutton where
user can choose both horse and pig. That means program should look for
either horse or pig in the samme row. and if program find either horse or
pig in one row + sTwo and Sthree insert that row in listbox.



With UserForm1

If Me.OptionButton1.Value Then
sOne = "Horse"
ElseIf Me.OptionButton2.Value Then
sOne = "Pig"
?????ElseIf Me.OptionButton5.Value Then
sOne = "Horse Or 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