PC Review


Reply
Thread Tools Rate Thread

Application 1004 error

 
 
headly
Guest
Posts: n/a
 
      23rd Jun 2008
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 With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      23rd Jun 2008
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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
run-time error '1004': Application-defined or object-deifined error rich5665@gmail.com Microsoft Excel Programming 5 10th Aug 2005 09:39 PM
Application Error 1004 ExcelMonkey Microsoft Excel Programming 4 9th Feb 2005 01:55 AM
Application / Object Error 1004 Garry Microsoft Excel Programming 7 6th Oct 2004 01:22 PM
Application error 1004 with a twist. Darren Lord Microsoft Excel Programming 1 22nd Aug 2003 12:30 PM
Application error 1004. Darren Microsoft Excel Programming 2 12th Aug 2003 09:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:41 AM.