Command Button

J

John Excel

I have a coomand button that should select a sheet and change the value in a
cell.
The code I have used is as follows, but it generates an error.

Private Sub CommandButton2_Click()
Sheets("Customer Profile").Select
Range("newused") = 1
End Sub

Please advise weere I am going wrong.

Thanks in advance of a favourable reply.
John
 
J

Jarek Kujawa

1. check if there is a worksheet named "Customer Profile" in yr
workbook
2. check if there is a range named "newused" in yr workbook
 
D

Dave Peterson

Since this code is behind a worksheet, any unqualified ranges will refer to the
worksheet that owns the code (and the button). And I bet that there isn't a
range named "NewUsed" on that sheet with the button.

You could use:

Sheets("Customer Profile").Select
sheets("customer profile").Range("newused") = 1

or (to save typing):

with Sheets("Customer Profile")
.Select
.Range("newused") = 1
end with

But it would be best to drop the select completely:
Sheets("Customer Profile").Range("newused") = 1



If the range is
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top