ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   This does not work: Range("A1").Select (https://www.excelbanter.com/excel-programming/285587-does-not-work-range-a1-select.html)

bob

This does not work: Range("A1").Select
 
Why do I get an error with this?


Private Sub CommandButton1_Click()
Sheets("Forecast").Select
Range("A1").Select
End Sub







Harald Staff

This does not work: Range("A1").Select
 
Hi

Probably because that code is in Sheet3. From there you have very limited power over
Sheet1. Put code like this in standard modules and call them from the sheets. Like:

Sub GoForecast()
Sheets("Forecast").Select
Range("A1").Select
End Sub

and in the sheet:

Private Sub CommandButton1_Click()
Call GoForecast
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please.

"Bob" wrote in message
...
Why do I get an error with this?


Private Sub CommandButton1_Click()
Sheets("Forecast").Select
Range("A1").Select
End Sub









Tom Ogilvy

This does not work: Range("A1").Select
 
Private Sub CommandButton1_Click()
Sheets("Forecast").Select
Range("A1").Select
End Sub


Because the unqualified Range("A1").Select refers to the sheet containing
the button which is not the active sheet

Private Sub CommandButton1_Click()
With Sheets("Forecast")
.Select
.Range("A1").Select
End Sub


Should work.

--
regards,
Tom Ogilvy


"Bob" wrote in message
...
Why do I get an error with this?


Private Sub CommandButton1_Click()
Sheets("Forecast").Select
Range("A1").Select
End Sub










All times are GMT +1. The time now is 10:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com