delete rows based on optionbutton criteria

Jam_Ica

New Member
Joined
Apr 12, 2011
Messages
7
I need to create a macro where a userform is populated with differnt option buttons. Once the user has made their selections, the buttons that were not selected need to erase rows in an excel spreadsheet. So if one option button was "french fries" and it was not selected, any row with "french fries" in column C needs to be erased. Any help would be great. Thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Welcome to the Board.
Maybe this is a start...
Code:
Private Sub CommandButton1_Click()
  Dim r As Long, Ctrl As Object, Rng As Range
  'set the data range to erase rows in
  Set Rng = Sheets("Sheet1").Range("A1").CurrentRegion
  For Each Ctrl In Me.Controls
    If TypeName(Ctrl) = "OptionButton" And Ctrl = False Then
      For r = 1 To Rng.Rows.Count
        If LCase(Rng.Cells(r, 3)) = LCase(Ctrl.Caption) Then
          Rng.Rows(r).EntireRow.ClearContents
        End If
      Next r
    End If
  Next Ctrl
End Sub
 
Upvote 0
I keep geeting an error at set Rng......also i have 8 different optionbuttons set up as choicea. Is there a way to be able to select more then one? Or should i use check boxes? ;)
 
Upvote 0
I keep geeting an error at set Rng......also i have 8 different optionbuttons set up as choicea. Is there a way to be able to select more then one? Or should i use check boxes?
I am guessing that your sheet isn't named "Sheet1".
If not, change that line of code to suit the name of your sheet.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

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