Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default option button-if else?

I wamt to make third option button where is possible to choose both horse
and pig. Whta I need to change in my code?

If .OptionButton1 Then
sOne = "Horse"
Else
sOne = "Pig"

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default option button-if else?

Is it on a userform? If so, then

If Me.OptionButton1.Value Then
sOne = "Horse"
Else
sOne = "Pig"
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Alen32" wrote in message
lkaboutsoftware.com...
I wamt to make third option button where is possible to choose both horse
and pig. Whta I need to change in my code?

If .OptionButton1 Then
sOne = "Horse"
Else
sOne = "Pig"



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default option button-if else?


I have 3 optionbutton
1.Horse
2.Pig
3.Both

This work only for first 2 buttons. What to change so third one also
work?

If Me.OptionButton1.Value Then
sOne = "Horse"
Else
sOne = "Pig"
End If


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default option button-if else?

Do you mean

If Me.OptionButton1.Value Then
sOne = "Horse"
ElseIf Me.Optionbutton2.Value Then
sOne = "Pig"
ElseIf Me.Optionbutton3.Value
sOne = "Horse & Pig"
End If

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Alen32" wrote in message
lkaboutsoftware.com...

I have 3 optionbutton
1.Horse
2.Pig
3.Both

This work only for first 2 buttons. What to change so third one also
work?

If Me.OptionButton1.Value Then
sOne = "Horse"
Else
sOne = "Pig"
End If




  #5   Report Post  
Posted to microsoft.public.excel.programming
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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default option button-if else?

How about this


With UserForm1

If .OptionButton1.Value Then
sOne = "Horse"
sOnePlus = ""
ElseIf .OptionButton2.Value Then
sOne = "Pig"
sOnePlus = ""
ElseIf .OptionButton5.Value Then
sOne = "Horse"
sOnePlus = "Pig"
End If


If .OptionButton3 Then
stwo = "Danish"
Else
stwo = "Foreign"
End If
sThree = .TextBox1.Text
End With

With Worksheets(1).Cells
Set c = Nothing
Set c = .Find(sOne, LookIn:=xlValues)
If c Is Nothing And stwo < "" Then
Set c = .Find(sOnePlus, 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 If
End With

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Alen32" wrote in message
lkaboutsoftware.com...
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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default option button-if else?

This makro doesn't fill listbox.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
keep source formatting is not an option in paste option button Tina Excel Discussion (Misc queries) 0 February 20th 06 09:58 PM
Getting value of Option button BG Excel Discussion (Misc queries) 2 September 27th 05 01:47 PM
Option Button Fable Excel Discussion (Misc queries) 1 August 16th 05 01:59 AM
Option Button Value ExcelMonkey[_190_] Excel Programming 1 February 20th 05 12:48 AM
VBA - Option Button ajliaks[_19_] Excel Programming 1 May 5th 04 02:56 AM


All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"