ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   write to column A depending on which Radio button is selected. (https://www.excelbanter.com/excel-programming/415552-write-column-depending-radio-button-selected.html)

Jim

write to column A depending on which Radio button is selected.
 
Hi everyone,

I have 4 radio buttons on a worksheet named right, left, front, and back. I
want Cells (selected.row, 1) to be given the value "right, left, front, or
back" depending on the button selected but only if they type text in that row
(in column B specifically) And if they erase the contents in row B then it
will erase as well. Thanks

Bob Bridges

write to column A depending on which Radio button is selected.
 
I don't fool with controls in Excel much - some, not much - but it seems to
me that if you've already attached code to each button selection then each
command just has to read something like this:

If ActiveSheet.Cells(ActiveCell.Row, 2) < "" then ActiveCell = SelectedValue

Something like that should set the value you want when the user clicks on
one of your radio buttons. If you want to change A back to blank when the
user deletes B, that takes a Change event; I've never written one but I
gather it would look like this:

Private Sub Worksheet_Change(ByVal ChgCell as Range)
If ChgCell.Column = 2 And ChgCell.Value = "" Then ChgCell.Offset(0, -1) = ""
End Sub

I think this goes in the worksheet code, not in an additional module, so you
don't have to check to be sure you're in the right worksheet too. But the
only Change event applies to any cell in the Worksheet, so the same Sub has
to be executed every time anyone types anything at all into the worksheet,
and the sub has to see which cell was changed and react only in certain
circumstances.

--- "Jim" wrote:
I have 4 radio buttons on a worksheet named right, left, front, and back. I
want Cells (selected.row, 1) to be given the value "right, left, front, or
back" depending on the button selected but only if they type text in that row
(in column B specifically) And if they erase the contents in row B then it
will erase as well. Thanks


Jim

write to column A depending on which Radio button is selected.
 
Thanks Bob, That is getting closer. I might be able to work with something
like this. But...............
What if they first select the OptionButton "Right", Type some stuff so it
placed "Right" in col A, Then Selected OptionButton "Left" and typed some
more stuff and it placed "left" in col A? Any suggestions? thanks

"Bob Bridges" wrote:

I don't fool with controls in Excel much - some, not much - but it seems to
me that if you've already attached code to each button selection then each
command just has to read something like this:

If ActiveSheet.Cells(ActiveCell.Row, 2) < "" then ActiveCell = SelectedValue

Something like that should set the value you want when the user clicks on
one of your radio buttons. If you want to change A back to blank when the
user deletes B, that takes a Change event; I've never written one but I
gather it would look like this:

Private Sub Worksheet_Change(ByVal ChgCell as Range)
If ChgCell.Column = 2 And ChgCell.Value = "" Then ChgCell.Offset(0, -1) = ""
End Sub

I think this goes in the worksheet code, not in an additional module, so you
don't have to check to be sure you're in the right worksheet too. But the
only Change event applies to any cell in the Worksheet, so the same Sub has
to be executed every time anyone types anything at all into the worksheet,
and the sub has to see which cell was changed and react only in certain
circumstances.

--- "Jim" wrote:
I have 4 radio buttons on a worksheet named right, left, front, and back. I
want Cells (selected.row, 1) to be given the value "right, left, front, or
back" depending on the button selected but only if they type text in that row
(in column B specifically) And if they erase the contents in row B then it
will erase as well. Thanks



All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com