View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Susan Susan is offline
external usenet poster
 
Posts: 1,117
Default Option Button with VB code, not working

you've got a couple of problems going on here. first is your
optionbutton value. if you are using a forms button in a spreadsheet,
below is the proper coding. the second thing is your deletion of rows
- you can't select or delete non-contiguous ranges/rows. you'll have
to do them one at a time. which will be hard to code because after
you delete the first bunch, the second bunch moves up four rows.

this works, but doesn't delete the second batch of rows you wanted,
because they've moved up 4 rows, as i mentioned.
==========================
Option Explicit

Sub garcia()

Sheets("Sheet1").Select

If Worksheets("Sheet1").OptionButtons("Option Button 2") _
.Enabled = True Then
Sheets("AR").Select
Range("a17:a20").EntireRow.Delete
Range("a35:a38").EntireRow.Delete
Range("A1").Select
End If

End Sub
=============================
but it might get you started.

as for these:
If OptionButton2 Then

if what? if it explodes? if it leaps off the computer screen? if it
turns yellow and starts speaking german? :) plus you will have to
identify it better, as in the sub above.
hope it helps!
susan



On Jul 25, 2:14*pm, pgarcia wrote:
Why dosn't this work? Thanks
* * Sheets("INPUT_A").Select

* * If OptionButton2.Value = True Then
* * * * Sheets("AR").Select
* * * * Rows("17:20,35:38,53:56,78:81,102:105,140:147,160: 167,181:187").Select
* * * * Selection.Delete Shift:=xlUp
* * * * Range("A1").Select
* * ElseIf OptionButton3.Value = True Then
* * * * Sheets("AR").Select
* * * * Range("7:8,25:26,43:44,68:69,92:93,136:137,156:157 ,176:177").Select
* * * * Selection.Delete Shift:=xlUp
* * * * Range("A1").Select
* * ElseIf OptionButton4.Value = True Then
* * * * Sheets("AR").Select
* * * * Range( _

"7:8,17:20,25:26,35:38,43:44,53:56,68:69,78:81,92: 93,102:105,136:137,140:14*7,160:163,164:167,176:17 7,180:187,156:157" _
* * * * * * ).Select
* * * * Selection.Delete Shift:=xlUp
* * * * Range("A1").Select
* * End If

* * Sheets("AR").Select
* * Range("A1").Select

or this:
* * If OptionButton2 Then
* * * * Call AR_GTD
* * ElseIf OptionButton3 Then
* * * * Call AR_Both
* * ElseIf OptionButton4 Then
* * * * Call AR_ECO
* * End If