Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Problem with macro: 1004 error

Ok... This should be simple enough. Basically the Macro grabs the
entire contents of a sheet, creates a new sheet in the workbook, and
then tries to manipulate that new sheet.

Problem is, 50% of the time, a 1004 Error occurs when it begins to
makes changes to the new sheet.

Here's the relevant code:

Sub Main
Cells.Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste
Columns("A:H").Select ' this line is where it screws up
<-----rest of code irrelevant / snipped-----
End Sub

The macro literally dies the 5th line into the code (sometimes).

Suggestions??? Any help will be greatly appreciated. As I stated,
sometimes it runs like a scalded dog. Other times it dies there.

Thanks,

-Jon Pickens

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Problem with macro: 1004 error

Give this a try...

Sub Main()
Dim wksTo As Worksheet
Dim wksFrom As Worksheet

Set wksFrom = ActiveSheet
Set wksTo = Sheets.Add
wksFrom.Cells.Copy wksTo.Range("A1")

wksTo.Select
wksTo.Columns("A:H").Select ' this line is where it screws up

End Sub

It defines the sheets that we are working with explicitly, which may have
been your problem...

HTH

" wrote:

Ok... This should be simple enough. Basically the Macro grabs the
entire contents of a sheet, creates a new sheet in the workbook, and
then tries to manipulate that new sheet.

Problem is, 50% of the time, a 1004 Error occurs when it begins to
makes changes to the new sheet.

Here's the relevant code:

Sub Main
Cells.Select
Selection.Copy
Sheets.Add
ActiveSheet.Paste
Columns("A:H").Select ' this line is where it screws up
<-----rest of code irrelevant / snipped-----
End Sub

The macro literally dies the 5th line into the code (sometimes).

Suggestions??? Any help will be greatly appreciated. As I stated,
sometimes it runs like a scalded dog. Other times it dies there.

Thanks,

-Jon Pickens


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Problem with macro: 1004 error

Thanks Jim... quick question. In your example, are "wksTo" and
"wksFrom" just your names for the two sheets?

I appreciate the quick reply.

-JP

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Problem with macro: 1004 error

Nevermind :-) I figured it out... Thanks!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM
naming tab macro error runtime error 1004 D Excel Programming 3 February 28th 05 01:32 AM
VBA VLookup Problem: Run-Time error '1004' hurlbut777 Excel Programming 4 February 5th 05 12:43 AM


All times are GMT +1. The time now is 02:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"