Can someone hepl at searching with Option Buttons in Excel VBA?

pedromna

New Member
Joined
Jun 7, 2016
Messages
1
I have a database with 2 columns like: (example)

<code>AA 6
VE 9
HE 18
AO 12
PF 7

The code to search the rows I want, and to clean the search is already done:

<code>Sub B2_Click()
Dim c As String
Dim l As Integer

c = "B"
l = 2
Do While Not IsEmpty(Range(c & l))
If Range(c & l) > Range("G2") Then
Range("B" & l).Interior.ColorIndex = 30
Range("A" & l).Interior.ColorIndex = 36
Range("B" & l).Font.ColorIndex = 2
End If
l = l + 1
Loop

If IsEmpty(Range("G2")) Then
Range("G1") = "Please insert value:"
Range("G1").Font.Bold = 1
Range("G1").Font.ColorIndex = 30
End If

End Sub


Sub B3_Click()
Dim c As String
Dim l As Integer
c = "B"
l = 2

Do While Not IsEmpty(Range(c & l))
Range("A" & l).Interior.ColorIndex = 0
Range("B" & l).Interior.ColorIndex = 0
Range("B" & l).Font.ColorIndex = 1
l = l + 1
Loop
Range("G2") = ""
Range("G1") = ""
End Sub

but i need to add two option buttons so I can choose if I want to search
for values > or < than the value on Range("G2"). Can someone
please help me how to write the search?</code></code>
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Write code like this

Code:
Sub option1()
Dim ctl As Object
Set ctl = Sheets("Sheet1").DrawingObjects("Option Button 1")
If ctl.Value = 1 Then 'if it is selected
    Call B2_Click
End If
End Sub

Then assign the macro to your option button.

You can duplicate the code for the click event for the > and < options.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top