1

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"
1
  • This is one of many instances where having Option Explicit at the top of your module would have helped diagnose the problem. The proximal cause is that you forgot to put A3 in quotes ("A3") on that line so in effect you're calling Cells(Empty) which will give you that particular error message. But what you actually want is described in @L42's answer. Commented May 19, 2014 at 7:44

2 Answers 2

1

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.
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.