Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting Code Erroring Out...

Status
Not open for further replies.

tweek312

Technical User
Dec 18, 2004
148
US
I have this routine which basically does some simple formatting by copying and pasting a row and then AutoFitting the contents of the selected sheets.

It keeps crashing with an "Object Defined Error" 1004.

My fear is that it does not like the selecting of a cell when more than one sheet is selected.

Please help me figure it out...

BTW... I am switching .ScreenUpdating on and off in routines prior to this...Could that generate an object error?

Thanks,

Tweek


Code:
Sub Fmt_Exclm()


Sheets("IP Runner Log").Select
    Rows("2:2").Select 'selects "to be" format row
    Selection.Copy 'copies format row
SelShts 'selects all ! sheets
     Range("A1").'***CRASHES HERE***
     ActiveSheet.Paste 'pastes format row
Cells.Select 'selects all cells in sheet
Selection.Columns.AutoFit 'autofits all columns in sheets with !

Sheets("IP Runner Log").Select


End Sub


Code:
Sub SelShts()
s = ""
For Each ws In Worksheets
    If ws.Name Like "!*" Then s = s & Chr(1) & ws.Name
Next ws
Sheets(Split(Mid(s, 2), Chr(1))).Select
End Sub
 
Is this a typo?
Code:
     Range("A1")[COLOR=red][b].[/b][/color]'***CRASHES HERE***
You added the dot operator after Range without a property or method descriptor.


Regards,
Mike
 
Sorry... Typo. Should have been .Select; must have goofed it when I added the '***CRASHES HERE***

But none the less.. it still crashes... :(

Code:
Sub Fmt_Exclm()


Sheets("IP Runner Log").Select
    Rows("2:2").Select 'selects "to be" format row
    Selection.Copy 'copies format row
SelShts 'selects all ! sheets
     Range("A1").Select '***CRASHES HERE***
     ActiveSheet.Paste 'pastes format row
Cells.Select 'selects all cells in sheet
Selection.Columns.AutoFit 'autofits all columns in sheets with !

Sheets("IP Runner Log").Select


End Sub
 
Re-creating your bit of code, I do not get an error. The copy/paste operation is successful. So I don't believe selecting multiple sheets is the problem, although I'd ask why?


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top