ALL WORKSHEETS SCROLLED TO TOP AND CELL A1 ACTIVE

egris52788

Board Regular
Joined
Mar 6, 2003
Messages
114
I am trying to write a macro that will scroll all worksheets in a workbook to the top and leave the cursor in cell A1. The number of sheets in each workbook may vary so, the macro must work no matter how many sheets. Any help is appreciated.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi,

How about this:
Code:
Sub ToTop()
Dim sCurCell As String
Dim WS As Worksheet, wsCur As Worksheet

Set wsCur = ActiveSheet
sCurCell = Selection.Address

For Each WS In ThisWorkbook.Worksheets
    WS.Select
    WS.Range("A1").Select
Next WS
wsCur.Select
Range(sCurCell).Select
End Sub
 
Upvote 0
DOESNT WORK

the macro does not do anything when I put the "on error resume next" line before the for loop
 
Upvote 0
Oh yes it does :¬)

Code:
Sub ToTop()
Dim sCurCell As String
Dim WS As Worksheet, wsCur As Worksheet

Set wsCur = ActiveSheet
sCurCell = Selection.Address

On Error Resume Next
For Each WS In ThisWorkbook.Worksheets
    WS.Select
    WS.Range("A1").Select
Next WS
wsCur.Select
Range(sCurCell).Select
End Sub
 
Upvote 0
youre right but..........

youre right..i was trying to run it from my personal macro workbook...is there a way to make work on another workbook from my personal macro workbook?
 
Upvote 0
Hi,

Try this:
Code:
Sub ToTop()
Dim sCurCell As String
Dim WS As Worksheet, wsCur As Worksheet

Set wsCur = ActiveSheet
sCurCell = Selection.Address

On Error Resume Next
For Each WS In ActiveWorkbook.Worksheets
    WS.Select
    WS.Range("A1").Select
Next WS
wsCur.Select
Range(sCurCell).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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