Range of object worksheet failed

SmallScreen

New Member
Joined
Apr 13, 2015
Messages
3
Hi,

I have a 2 page spreadsheet. On page 1 I have a table counting the number of yes and no votes. Sheet1!B2 contains number of Yes votes, Sheet1!B3 number of No votes.

In Sheet 2 I've created two buttons, one increases the yes count by one, and the other the no count by one. I first created these as forms buttons and they worked, but realised I couldn't edit the colour of the buttons so went to create them in ActiveX instead.

I've created the buttons using this code:

Private Sub CommandButton1_Click()
Range("Sheet1!B3") = Range("Sheet1!B3").Value + 1
End Sub

When I click the button, it generates the error: Method 'Range' of object '_Worksheet' failed.

I'm a complete noob and just making this up as I go along, so appreciate ELI5 instructions!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Works fine for me. Got a protected worksheet, or merged cells?
 
Upvote 0
Try:
Code:
Private Sub CommandButton1_Click()
With Sheets("Sheet1")
    .Range("B3") = .Range("B3") + 1
End With
End Sub
 
Upvote 0
Try:-
Code:
Private Sub CommandButton1_Click()
With Sheets("Sheet1").Range("B3")
    .Value = .Value + 1
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,395
Messages
6,119,265
Members
448,881
Latest member
Faxgirl

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