Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
RJB RJB is offline
external usenet poster
 
Posts: 86
Default Running code from form button

I would like to have a form where when a question is asked, if you click the
radio button (er, "Form Toolbox 'Option' button"), you will get different
results based on whether or not you click "Yes" or "No". (Separate buttons -
one for "yes" and one for "no")

I've assigned the Format control cell link to a certain cell, and then
written code referencing the value of that cell.

If I simply TYPE a "1" or a "2" in that cell (cell D8), the code runs fine.
But clicking the radio button (which changes the value of that cell to "1" or
"2") does nothing.

Is there a way to accomplish this?

Here's the code:

==========================
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$8" Then
If Target.Value = "2" Then
Application.Goto reference:="N", Scroll:=True
ElseIf Target.Value = "1" Then
Application.Goto reference:="Answer_A", Scroll:=True
End If
End If
==========================

Thanks for the help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Running code from form button

hi,
The reason you are having trouble is that you are using the worksheet change
event. this doesn't work on controls, only on the sheet itself. Controls have
their own events, independent from worksheet and workbook events. I suggest
that you move the code to the option button's click or change event. (not
sure which....i didn't test)

good luck
regards
FSt1

"RJB" wrote:

I would like to have a form where when a question is asked, if you click the
radio button (er, "Form Toolbox 'Option' button"), you will get different
results based on whether or not you click "Yes" or "No". (Separate buttons -
one for "yes" and one for "no")

I've assigned the Format control cell link to a certain cell, and then
written code referencing the value of that cell.

If I simply TYPE a "1" or a "2" in that cell (cell D8), the code runs fine.
But clicking the radio button (which changes the value of that cell to "1" or
"2") does nothing.

Is there a way to accomplish this?

Here's the code:

==========================
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$8" Then
If Target.Value = "2" Then
Application.Goto reference:="N", Scroll:=True
ElseIf Target.Value = "1" Then
Application.Goto reference:="Answer_A", Scroll:=True
End If
End If
==========================

Thanks for the help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
RJB RJB is offline
external usenet poster
 
Posts: 86
Default Running code from form button

In other words, write an individual macro for each click?

"FSt1" wrote:

hi,
The reason you are having trouble is that you are using the worksheet change
event. this doesn't work on controls, only on the sheet itself. Controls have
their own events, independent from worksheet and workbook events. I suggest
that you move the code to the option button's click or change event. (not
sure which....i didn't test)

good luck
regards
FSt1

"RJB" wrote:

I would like to have a form where when a question is asked, if you click the
radio button (er, "Form Toolbox 'Option' button"), you will get different
results based on whether or not you click "Yes" or "No". (Separate buttons -
one for "yes" and one for "no")

I've assigned the Format control cell link to a certain cell, and then
written code referencing the value of that cell.

If I simply TYPE a "1" or a "2" in that cell (cell D8), the code runs fine.
But clicking the radio button (which changes the value of that cell to "1" or
"2") does nothing.

Is there a way to accomplish this?

Here's the code:

==========================
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$D$8" Then
If Target.Value = "2" Then
Application.Goto reference:="N", Scroll:=True
ElseIf Target.Value = "1" Then
Application.Goto reference:="Answer_A", Scroll:=True
End If
End If
==========================

Thanks for the help.

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
how to prevent code running when in a worksheet code Corey Excel Programming 5 August 13th 06 08:52 AM
Command Button vs Form Button Bri[_3_] Excel Programming 2 February 3rd 06 08:18 AM
User Form Button Code Debs Excel Programming 1 February 26th 04 12:13 PM
Running command button click event code Marishah Warren Excel Programming 1 December 31st 03 07:53 AM
Command Button vs Form Button T K Excel Programming 4 August 26th 03 07:26 PM


All times are GMT +1. The time now is 03:43 PM.

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

About Us

"It's about Microsoft Excel"