Formatting workbook and going to first sheet

  • Thread starter Thread starter Stav19
  • Start date Start date
S

Stav19

Hi All

Fairly straightforward question I think, basically I want a little
macro to format a workbook I have open. It will select "A1" in each
sheet and then return to the first sheet. This is what I have:

Dim i As Integer
wksname = ActiveSheet.Name

For i = 1 To Sheets.Count
Sheets(i).Select
Range("A1").Select

Next i

'Sheets(wksname).Activate

unfortunately I get a "run time error 1004" message saying "Select
method of workclass failed".

Can anyone shed any light?
Cheers in advance
 
Hi,

This will select A1 of each sheet but you don't say what you want to do. In
any case it's highly inlikely you need to select the cell, you can format it
without selecting

This goes in a general module

Sub Dont_Select()
Dim i As Integer
wksname = Sheets(1).Name
For i = 1 To Worksheets.Count
Sheets(i).Select
Range("A1").Select
Next i
Sheets(wksname).Activate
End Sub

Mike
 
Careful - this may fail if there are any Chart or Macro sheets in the
workbook.

Try

Worksheets(i).Select

instead of

Sheets(i).Select
 
Careful - this may fail if there are any Chart or Macro sheets in the
workbook.

Try

   Worksheets(i).Select

instead of

   Sheets(i).Select






- Show quoted text -

cheers for your help, I'll have to give that a go!!!
 

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

Back
Top