A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Run-time error: '1004'



 
 
Thread Tools Display Modes
  #1  
Old May 21st, 2009, 02:13 PM posted to microsoft.public.excel.worksheet.functions
bishop
external usenet poster
 
Posts: 48
Default Run-time error: '1004'

I'm getting a 1004 runtime error for the following line of code:

CDLastRow = Workbooks("Test Tally SheetII").Worksheets("Catalyst
Dump").Range("A" & Rows.Count).End(xlUp).Row

I'm trying to get the sub routine to work no matter what sheet/workbook I'm
in. Here is the complete code:

Sub CatalystToTally()

Dim wb As Workbook
Dim ws As Worksheet
Dim CDLastRow As Integer 'Catalyst Dump
Dim EDLastRow As Integer 'Exported Data

CDLastRow = Workbooks("Test Tally SheetII").Worksheets("Catalyst
Dump").Range("A" & Rows.Count).End(xlUp).Row
Worksheets("Catalyst Dump").Columns("D").ColumnWidth = 13

For Each wb In Workbooks
'Test to see if wb's name is like "ExportedData*"
If wb.Name Like "ExportedData*" Then
'Create a worksheet object to reference the appropriate
'worksheet in the wb
Set ws = wb.ActiveSheet

With ws
.Rows("1:1").Delete Shift:=xlUp
EDLastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Columns("D").ColumnWidth = 13
.Columns("D").NumberFormat = "0"
.Rows("1:" & EDLastRow).Copy ThisWorkbook.Worksheets _
("Catalyst Dump").Rows(CDLastRow + 1)
End With
wb.Close savechanges:=False
End If
Next
End Sub
  #2  
Old May 21st, 2009, 02:24 PM posted to microsoft.public.excel.worksheet.functions
Jacob Skaria
external usenet poster
 
Posts: 5,952
Default Run-time error: '1004'

Try the below...... (.xls)

Dim CDLastRow As Long 'Catalyst Dump
Dim EDLastRow As Long 'Exported Data

CDLastRow = Workbooks("Test Tally SheetII.xls").Worksheets _
("Catalyst Dump").Cells(Rows.Count, "A").End(xlUp).Row
Worksheets("Catalyst Dump").Columns("D").ColumnWidth = 13

If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

I'm getting a 1004 runtime error for the following line of code:

CDLastRow = Workbooks("Test Tally SheetII").Worksheets("Catalyst
Dump").Range("A" & Rows.Count).End(xlUp).Row

I'm trying to get the sub routine to work no matter what sheet/workbook I'm
in. Here is the complete code:

Sub CatalystToTally()

Dim wb As Workbook
Dim ws As Worksheet
Dim CDLastRow As Integer 'Catalyst Dump
Dim EDLastRow As Integer 'Exported Data

CDLastRow = Workbooks("Test Tally SheetII").Worksheets("Catalyst
Dump").Range("A" & Rows.Count).End(xlUp).Row
Worksheets("Catalyst Dump").Columns("D").ColumnWidth = 13

For Each wb In Workbooks
'Test to see if wb's name is like "ExportedData*"
If wb.Name Like "ExportedData*" Then
'Create a worksheet object to reference the appropriate
'worksheet in the wb
Set ws = wb.ActiveSheet

With ws
.Rows("1:1").Delete Shift:=xlUp
EDLastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Columns("D").ColumnWidth = 13
.Columns("D").NumberFormat = "0"
.Rows("1:" & EDLastRow).Copy ThisWorkbook.Worksheets _
("Catalyst Dump").Rows(CDLastRow + 1)
End With
wb.Close savechanges:=False
End If
Next
End Sub

  #3  
Old May 21st, 2009, 04:28 PM posted to microsoft.public.excel.worksheet.functions
bishop
external usenet poster
 
Posts: 48
Default Run-time error: '1004'

Still giving me an Run-time error: '9' Subscript out of range. I changed it
per your instruction:

Dim CDLastRow As Long 'Catalyst Dump
Dim EDLastRow As Long 'Exported Data

CDLastRow = Workbooks("Test Tally SheetII.xlsm").Worksheets _
("Catalyst Dump").Cells(Rows.Count, "A").End(xlUp).Row
Worksheets("Catalyst Dump").Columns("D").ColumnWidth = 13

Since I'm working in 07 and my sheet is saved as .xlsm I used that instead
of .xls. But it locks up on this line still.

"Jacob Skaria" wrote:

Try the below...... (.xls)

Dim CDLastRow As Long 'Catalyst Dump
Dim EDLastRow As Long 'Exported Data

CDLastRow = Workbooks("Test Tally SheetII.xls").Worksheets _
("Catalyst Dump").Cells(Rows.Count, "A").End(xlUp).Row
Worksheets("Catalyst Dump").Columns("D").ColumnWidth = 13

If this post helps click Yes
---------------
Jacob Skaria


"Bishop" wrote:

I'm getting a 1004 runtime error for the following line of code:

CDLastRow = Workbooks("Test Tally SheetII").Worksheets("Catalyst
Dump").Range("A" & Rows.Count).End(xlUp).Row

I'm trying to get the sub routine to work no matter what sheet/workbook I'm
in. Here is the complete code:

Sub CatalystToTally()

Dim wb As Workbook
Dim ws As Worksheet
Dim CDLastRow As Integer 'Catalyst Dump
Dim EDLastRow As Integer 'Exported Data

CDLastRow = Workbooks("Test Tally SheetII").Worksheets("Catalyst
Dump").Range("A" & Rows.Count).End(xlUp).Row
Worksheets("Catalyst Dump").Columns("D").ColumnWidth = 13

For Each wb In Workbooks
'Test to see if wb's name is like "ExportedData*"
If wb.Name Like "ExportedData*" Then
'Create a worksheet object to reference the appropriate
'worksheet in the wb
Set ws = wb.ActiveSheet

With ws
.Rows("1:1").Delete Shift:=xlUp
EDLastRow = .Range("A" & Rows.Count).End(xlUp).Row
.Columns("D").ColumnWidth = 13
.Columns("D").NumberFormat = "0"
.Rows("1:" & EDLastRow).Copy ThisWorkbook.Worksheets _
("Catalyst Dump").Rows(CDLastRow + 1)
End With
wb.Close savechanges:=False
End If
Next
End Sub

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:26 PM.


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