#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default VBA error

I get an error, "Run-time error '1004': Application-defined or object-defined
error" when I run the following macro:

Sub Sheet_Names()
Dim ws As Worksheet
With Worksheets.Add
.Name = "Sheet Names"
.Move befo=Worksheets(1)
End With
Sheets("Sheet Names").Activate
Range("a1").Activate
For Each ws In Worksheets
If ws.Name < "Sheet Names" Then
ActiveCell.Formula = ws.Name
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub

What does this error mean and how can I resolve it? The macro is supposed
to create a list of tab names in the workbook.

Thanks,

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,311
Default VBA error

Your code works for me. Where does it fail?


"Dave F" wrote in message
...
I get an error, "Run-time error '1004': Application-defined or
object-defined
error" when I run the following macro:

Sub Sheet_Names()
Dim ws As Worksheet
With Worksheets.Add
.Name = "Sheet Names"
.Move befo=Worksheets(1)
End With
Sheets("Sheet Names").Activate
Range("a1").Activate
For Each ws In Worksheets
If ws.Name < "Sheet Names" Then
ActiveCell.Formula = ws.Name
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub

What does this error mean and how can I resolve it? The macro is supposed
to create a list of tab names in the workbook.

Thanks,

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default VBA error

Hi dave

Copy the macro in a normal module and not in a sheet module

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dave F" wrote in message ...
I get an error, "Run-time error '1004': Application-defined or object-defined
error" when I run the following macro:

Sub Sheet_Names()
Dim ws As Worksheet
With Worksheets.Add
.Name = "Sheet Names"
.Move befo=Worksheets(1)
End With
Sheets("Sheet Names").Activate
Range("a1").Activate
For Each ws In Worksheets
If ws.Name < "Sheet Names" Then
ActiveCell.Formula = ws.Name
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub

What does this error mean and how can I resolve it? The macro is supposed
to create a list of tab names in the workbook.

Thanks,

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default VBA error

Thanks. So, basic question: how do you know when a block of code should be
contained in its own module?

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Ron de Bruin" wrote:

Hi dave

Copy the macro in a normal module and not in a sheet module

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dave F" wrote in message ...
I get an error, "Run-time error '1004': Application-defined or object-defined
error" when I run the following macro:

Sub Sheet_Names()
Dim ws As Worksheet
With Worksheets.Add
.Name = "Sheet Names"
.Move befo=Worksheets(1)
End With
Sheets("Sheet Names").Activate
Range("a1").Activate
For Each ws In Worksheets
If ws.Name < "Sheet Names" Then
ActiveCell.Formula = ws.Name
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub

What does this error mean and how can I resolve it? The macro is supposed
to create a list of tab names in the workbook.

Thanks,

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,123
Default VBA error

Hi Dave

Always copy macros in a normal module
Sheet modules are for events for the sheet or controls on the sheet.

See this page
http://www.cpearson.com/excel/codemods.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dave F" wrote in message ...
Thanks. So, basic question: how do you know when a block of code should be
contained in its own module?

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Ron de Bruin" wrote:

Hi dave

Copy the macro in a normal module and not in a sheet module

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dave F" wrote in message ...
I get an error, "Run-time error '1004': Application-defined or object-defined
error" when I run the following macro:

Sub Sheet_Names()
Dim ws As Worksheet
With Worksheets.Add
.Name = "Sheet Names"
.Move befo=Worksheets(1)
End With
Sheets("Sheet Names").Activate
Range("a1").Activate
For Each ws In Worksheets
If ws.Name < "Sheet Names" Then
ActiveCell.Formula = ws.Name
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub

What does this error mean and how can I resolve it? The macro is supposed
to create a list of tab names in the workbook.

Thanks,

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.




  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,574
Default VBA error

Exactly the info I was looking for, thanks.

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Ron de Bruin" wrote:

Hi Dave

Always copy macros in a normal module
Sheet modules are for events for the sheet or controls on the sheet.

See this page
http://www.cpearson.com/excel/codemods.htm



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dave F" wrote in message ...
Thanks. So, basic question: how do you know when a block of code should be
contained in its own module?

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


"Ron de Bruin" wrote:

Hi dave

Copy the macro in a normal module and not in a sheet module

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Dave F" wrote in message ...
I get an error, "Run-time error '1004': Application-defined or object-defined
error" when I run the following macro:

Sub Sheet_Names()
Dim ws As Worksheet
With Worksheets.Add
.Name = "Sheet Names"
.Move befo=Worksheets(1)
End With
Sheets("Sheet Names").Activate
Range("a1").Activate
For Each ws In Worksheets
If ws.Name < "Sheet Names" Then
ActiveCell.Formula = ws.Name
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub

What does this error mean and how can I resolve it? The macro is supposed
to create a list of tab names in the workbook.

Thanks,

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.


  #7   Report Post  
Posted to microsoft.public.excel.misc
bj bj is offline
external usenet poster
 
Posts: 1,397
Default VBA error

this is a problem which occassionally shows up when you copy sheets often
without saving the workbook
try saving thew workbook and try running the macro again. It works fine for
me 2003

"Dave F" wrote:

I get an error, "Run-time error '1004': Application-defined or object-defined
error" when I run the following macro:

Sub Sheet_Names()
Dim ws As Worksheet
With Worksheets.Add
.Name = "Sheet Names"
.Move befo=Worksheets(1)
End With
Sheets("Sheet Names").Activate
Range("a1").Activate
For Each ws In Worksheets
If ws.Name < "Sheet Names" Then
ActiveCell.Formula = ws.Name
ActiveCell.Offset(1, 0).Select
End If
Next
End Sub

What does this error mean and how can I resolve it? The macro is supposed
to create a list of tab names in the workbook.

Thanks,

Dave
--
A hint to posters: Specific, detailed questions are more likely to be
answered than questions that provide no detail about your problem.

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
Error: "Excel encountered an error and had to remove some formatti Carl Excel Discussion (Misc queries) 0 September 18th 06 06:39 PM
Counting instances of found text (Excel error? Or user error?) S Davis Excel Worksheet Functions 5 September 12th 06 04:52 PM
I have Error 1919 Error Configuring ODBC dataSource Database Texanna1 Excel Discussion (Misc queries) 1 September 12th 06 06:35 AM
Excel 2003 Macro Error - Runtime error 1004 Cow Excel Discussion (Misc queries) 2 June 7th 05 01:40 PM


All times are GMT +1. The time now is 04:37 PM.

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

About Us

"It's about Microsoft Excel"