radio button with VB code

P

pgarcia

Hello all,
I’m needing the following: 4 radio buttons, “Defaultâ€, “GTDâ€, “ECOâ€, “BOTHâ€.
When running a VB code, I need to code to look at what button has been
selected and call another VB code or in the case of “Default†it keeps
running the code with out interruption.
So, VB code is running, then it looks at the radio buttons, see that “GTDâ€
is select and then calls another VB code, then it continues on with the rest
of the code when the other code is finished.

Thanks
 
J

Jim Thomlinson

assuming you have grabbed option buttons from the control toolbox code like
this might do it...

Sub test()
If OptionButton1 Then
MsgBox OptionButton1.Name
ElseIf OptionButton2 Then
MsgBox OptionButton2.Name
ElseIf OptionButton3 Then
MsgBox OptionButton3.Name
ElseIf OptionButton4 Then
MsgBox OptionButton1.Name
Else
MsgBox "none"
End If
End Sub
 
P

pgarcia

Thanks, this is what I did and what I need it for, but it did not work like I
want it to. It does not bring up the "Call" VB codes. Could you take a look
at it for me and point out what I'm doing wrong? Thanks

Sheets("INPUT_A").Select
If OptionButton2 Then
Call AR_GTD
ElseIf OptionButton3 Then
Call AR_Both
ElseIf OptionButton4 Then
Call AR_ECO
End If

It should run one the following:
Sub AR_GTD()

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
End Sub


Sub AR_ECO()

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
End Sub


Sub AR_Both()

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:147,160:163,164:167,176:177,180:187,156:157" _
).Select
Selection.Delete Shift:=xlUp
Range("A1").Select
End Sub

And this is what the whole code is:

Sub Copy_Paste_AR()
'
Application.ScreenUpdating = False

Sheets("AR").Visible = True

Dim MyPath As String
Dim MyFileName As String

Sheets("AR").Select
Range("H1:H187", Range("H1:H187").End(xlDown)).Copy
Range("H1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Columns("A:G").Delete Shift:=xlToLeft

Sheets("INPUT_A").Select

If OptionButton2 Then
Call AR_GTD
ElseIf OptionButton3 Then
Call AR_Both
ElseIf OptionButton4 Then
Call AR_ECO
End If

Sheets("AR").Select

MyPath = "S:\SUPPORT\CADTAR\CMS\!Exported_Text_Files!\"
MyFileName = "d" & Sheets("INPUT_A").Range("C8").Value & "ar"

ActiveWorkbook.SaveAs Filename:=MyPath & MyFileName, _
FileFormat:=xlText, CreateBackup:=False

Sheets("INPUT_A").Select
MsgBox ("AR file has been created at:" & vbLf &
"S:\SUPPORT\CADTAR\CMS\!Exported_Text_Files!\")

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top