How To Automatically Set the Cursor on cell a1 on file open

kfotedar

New Member
Joined
Aug 13, 2004
Messages
31
Hi!,

Is there any way through VB code I could get the cursor to be on cell A1 when I open the excel file. My file has 10 sheets and I wanted that he cursor should be on cell a1 when any sheet on the file is selected.

Thanks,

Kavir
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hit ALT+F11 to open VBA.
Select: 'This Workbook' in the VBA Project's 'Miscrosoft Excel Objects' (upper left window)

In large right window put the following code:

Private Sub Workbook_Open()
Sheet1.Range("A1").Select
End Sub

This will select A1 when Workbook opens.
 
Upvote 0
This only puts the cursor on cell a1 for sheet1. I've 10 sheets in the workbook, i want the cursor to be on a1 for every sheet when the workbook is opened.

Thanks.

K
 
Upvote 0
You can use the following to set all sheets to "A1"
<code>
Private Sub Workbook_Open()
For Each ws In ActiveWorkbook.Sheets
Worksheets.Select
Range("A1").Activate
Next ws
End Sub
</code>
 
Upvote 0
Private Sub Workbook_Open()
Dim WSheet As Worksheet

For Each WSheet In Worksheets
WSheet.Activate
Range("A1").Select
Next
End Sub

(y)
 
Upvote 0
Private Sub Workbook_Open()
Dim WSheet As Worksheet

For Each WSheet In Worksheets
WSheet.Activate
Range("A1").Select
Next
End Sub

(y)

Hello Ziggy12,

I really do like your approach and I've tried it out and it is working perfectly.

However, can you please add to your code above:

Where;

If the Sheet is EVEN
Code:
Range("A2").Select
likewise If the
Code:
Sheet is ODD Range("B3").Select
??

I've tried what I think would work but I'm not getting what I am after.

Many thanks,
Pinaceous
 
Upvote 0
Hi,

I had a go at this out of interest and here's my tuppence worth.

this works using the worksheet index.

Code:
For Each WSheet In Worksheets
 WSheet.Activate
 
 n = WSheet.Index
 If n Mod 2 = 0 Then

 Range("A2").Select
 Else
 Range("B3").Select
 End If
 
 Next
 
Last edited:
Upvote 0

Forum statistics

Threads
1,218,270
Messages
6,141,471
Members
450,361
Latest member
Barnaby2024

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