user1787114
user1787114

Reputation: 205

assign cell value based on radio button selection

i am trying to assign a value to a cell when the user selects a radio button, the value changes depending on the radio selected. The radio buttons are on a form and i am trying to assign the value to a sheet called "Workspace"

here is the code i have

Private Sub OK_Click()
    'A3 Assignment
    If OpQ1_01_1.Value = True Then
    Sheets("Workpace").Cells("A3").Value = "1"
    ElseIf OpQ1_01_2.Value = True Then
    Sheets("Workpace").Cells("A3").Value = "2"
    ElseIf OpQ1_01_3.Value = True Then
    Sheets("Workspace").Cells(A3).Value = "3"
    ElseIf OpQ1_01_4.Value = True Then
    Sheets("Workpace").Cells("A3").Value = "4"
    ElseIf OpQ1_01_5.Value = True Then
    Sheets("Workpace").Cells("A3").Value = "5"
    ElseIf OpQ1_01_6.Value = True Then
    Sheets("Workpace").Cells("A3").Value = "6"
    End If

as far as i can tell it should work, the sheet is there and theres a cell A3, but i keep getting a message stating "application-defined or object-defined error" which isnt telling me anything, but it highlights the assign part of the code for the radio button I selected (in this case the third option)

debug highlights this chunk of code in this case

Sheets("Workspace").Cells(A3).Value = "3"

Upvotes: 1

Views: 16422

Answers (2)

guest
guest

Reputation: 11

The name of the sheet seems to be missing an "s" in your code (you typed "Workpace" in the code instead of "Workspace"

Upvotes: 1

L42
L42

Reputation: 19727

Change Cells to Range like this:

Sheets("Workspace").Range("A3").Value = "3"

or if you want to stick to Cells like this:

Sheets("Workspace").Cells(3, 1).Value = "3"
'~~> where 3 is the row number and 1 is the column number.

Upvotes: 1

Related Questions