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"
Option Explicitat the top of your module would have helped diagnose the problem. The proximal cause is that you forgot to putA3in quotes ("A3") on that line so in effect you're callingCells(Empty)which will give you that particular error message. But what you actually want is described in @L42's answer.