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

This is spooky; This code works on some machines, but on others it throws a
1004 Application Defined Error;

Here's the code, any idea what's broken?

Public Sub ParseProduct()

'Separate products to sheets

'Goto starting cell
Range("b2").Select
'Navigate to bottom, get end cell
Selection.End(xlDown).Select

'Store end row in a variable
Dim varlastrow As Variant
varlastrow = ActiveCell.Row

'Go back to starting cell
Range("b2").Select

'Get the data sheet name
Dim varsheetname As Variant
varsheetname = ActiveSheet.Name

'Loop from row 2 to end row
Dim i As Variant 'i is a counter
For i = 2 To varlastrow

'Select the product in the variable row
Range("b" & i).Select

'Store the value in a variable
Dim varproduct As Variant
varproduct = Range("B" & i).Value

'create a variable to test true
Dim vartrue As Variant
vartrue = False

'Loop through sheets, test if product sheet exists
Dim k As Variant 'k is a counter

For k = 1 To Worksheets.Count
Worksheets(k).Select

If ActiveSheet.Name = varproduct Then
vartrue = True
End If

Next k
'if no product sheet
'add sheet, name the sheet
'and copy the header to the new sheet
If vartrue = False Then
Worksheets.Add
ActiveSheet.Name = varproduct
Worksheets(varsheetname).Select
Rows("1:1").Select
Selection.Copy
Worksheets(varproduct).Select
Rows("1:1").Select
ActiveSheet.Paste
End If

'Go back to data sheet
Worksheets(varsheetname).Select
'Copy the variable product to the product sheet
Rows(i).Select
Selection.Copy
Worksheets(varproduct).Select
Range("a65000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste

'Go back to data sheet
Worksheets(varsheetname).Select

Next i
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Application 1004 error

What line is throwing the error?

"headly" wrote:

This is spooky; This code works on some machines, but on others it throws a
1004 Application Defined Error;

Here's the code, any idea what's broken?

Public Sub ParseProduct()

'Separate products to sheets

'Goto starting cell
Range("b2").Select
'Navigate to bottom, get end cell
Selection.End(xlDown).Select

'Store end row in a variable
Dim varlastrow As Variant
varlastrow = ActiveCell.Row

'Go back to starting cell
Range("b2").Select

'Get the data sheet name
Dim varsheetname As Variant
varsheetname = ActiveSheet.Name

'Loop from row 2 to end row
Dim i As Variant 'i is a counter
For i = 2 To varlastrow

'Select the product in the variable row
Range("b" & i).Select

'Store the value in a variable
Dim varproduct As Variant
varproduct = Range("B" & i).Value

'create a variable to test true
Dim vartrue As Variant
vartrue = False

'Loop through sheets, test if product sheet exists
Dim k As Variant 'k is a counter

For k = 1 To Worksheets.Count
Worksheets(k).Select

If ActiveSheet.Name = varproduct Then
vartrue = True
End If

Next k
'if no product sheet
'add sheet, name the sheet
'and copy the header to the new sheet
If vartrue = False Then
Worksheets.Add
ActiveSheet.Name = varproduct
Worksheets(varsheetname).Select
Rows("1:1").Select
Selection.Copy
Worksheets(varproduct).Select
Rows("1:1").Select
ActiveSheet.Paste
End If

'Go back to data sheet
Worksheets(varsheetname).Select
'Copy the variable product to the product sheet
Rows(i).Select
Selection.Copy
Worksheets(varproduct).Select
Range("a65000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste

'Go back to data sheet
Worksheets(varsheetname).Select

Next i
End Sub

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
runtime error '1004' application or object defined error. Please help deej Excel Programming 0 August 1st 07 09:26 AM
Run Time Error 1004: Application or Object Defined Error BEEJAY Excel Programming 4 October 18th 06 04:19 PM
Run Time 1004 Error: Application or Object Difine Error BEEJAY Excel Programming 0 October 17th 06 10:45 PM
Error 1004, Application-definded or object-defined error Mirco Wilhelm[_2_] Excel Programming 9 January 7th 06 04:56 PM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


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

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"