error438: Object doesn't support this property or method (OptionButtons in a Range)

vywes

New Member
Joined
Dec 30, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
SmallMediumLarge
Option Button 1Option Button 2Option Button 3
Option Button 4Option Button 5Option Button 6
Using the group box, option button 1-3 is grouped as one group; 4-6 as another; and the next rows follow the same trend.

I'm trying to write the VBA so that in range F2:H5, for each row, if the Option Button in the left column is checked then cell.Offset(0,4).value=[a formula]; if option button in the middle column is checked then cell.Offset(0,3).value=[another formula]; if option button in the right column is checked then cell.Offset(0,2).value = [another formula]

I'm fairly new to VBA so am trying to piece together what I can and have come up with this so far:

VBA Code:
Sub ServingSize()

Dim rng As Range, cell As Range
Set rng = Range("H14:J16")

Dim rng1 As Range, cell1 As Range
Set rng1 = Range("H14:H16")

Dim rng2 As Range, cell2 As Range
Set rng2 = Range("I14:I16")

Dim rng3 As Range, cell3 As Range
Set rng3 = Range("J14:J16")

For Each cell In rng
If Range("rng1").cell1.OptionButton = True Then
cell.Offset(0, 4).Value = cell.Offset(0, 3).Value * 0.5
ElseIf Range("rng2").cell2.OptionButton = True Then
cell.Offset(0, 3).Value = cell.Offset(0, 2).Value
ElseIf Range("rng3").cell3.OptionButton = True Then
cell.Offset(0, 2).Value = cell.Offset(0, 1).Value * 1.5
End If
Next cell

End Sub

What did I do wrong here?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
See posts here (esp. 3,6,14,15). Maybe that thread will guide you.
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top