Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Run Time error '1004': Application-defined or object-defined error

I have the following line of code* causing the above error:

sht.activate

*sht.Range(Cells(rwn, 3), Cells(rwn, sht.UsedRange.Columns.Count)).Copy

this is within a for-next loop:

For Each sht In ThisWorkbook.Worksheets
next sht

rwn is an integer from a line within a another for-next loop:

rwn = cll.row

why is this causing an error?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Run Time error '1004': Application-defined or object-defined error

Hi

Nothing wrong with the line in question, but I think that the variable rwn
is empty, causing the error.

BTW: Please post the entire code, as it's eaysier to locate the error.

Regards,
Per

"PBcorn" skrev i meddelelsen
...
I have the following line of code* causing the above error:

sht.activate

*sht.Range(Cells(rwn, 3), Cells(rwn, sht.UsedRange.Columns.Count)).Copy

this is within a for-next loop:

For Each sht In ThisWorkbook.Worksheets
next sht

rwn is an integer from a line within a another for-next loop:

rwn = cll.row

why is this causing an error?


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Run Time error '1004': Application-defined or object-defined e


Full code below

the purpose of the macro is to insert a row above certain row labels (in col
2), add a new row label for this row, then add together two particualr
existing rows and paste into the new row. (using pastespecial add operation).
Note that the row labels are repeated once in each sheet.The data looks like:


col2: month1 month2 month3...........................
rowlabel1
rowlabel2
rowlabel3
rowlabel4
rowlabel5
rowlabel1
rowlabel2
rowlabel3
rowlabel4
rowlabel5




Sub tst()

Dim sht As Worksheet
Dim cll As Range
Dim r As Integer
Dim c As Integer
Dim rwn As Integer
Dim rwn2 As Integer
Dim rwn3 As Integer
Dim rwn4 As Integer
Dim rwn5 As Integer
Dim rwn6 As Integer
Dim counter As Integer


'for each "name" extract

For Each sht In ThisWorkbook.Worksheets

If Trim(sht.Range("a1").Value) = "name" Then

'insert new rows just below "CANC"

For Each cll In sht.UsedRange.Columns(2).Cells

If cll.Row = 2 Then

If Trim(cll.Value) = "DECLINED" And cll.Offset(-1, 0) < 0 And
cll.Offset(-1, 0).Value < "CANC+NTU" Then

cll.EntireRow.Insert
cll.Offset(-1, 0).Value = "CANC+NTU"

Else: End If
Else: End If


Next cll

'get row numbers of ranges to be added together

For Each cll In sht.UsedRange.Columns(2).Cells

If cll.Value = "CANC" Or cll.Value = "NTU" Or cll.Value =
"CANC+NTU" Then

counter = counter + 1


If counter = 1 Or counter = 2 Or counter = 3 Then

Select Case Trim(cll.Value)

Case Is = "CANC"
rwn = cll.Row

Case Is = "NTU"
rwn2 = cll.Row

Case Is = "CANC+NTU"
rwn3 = cll.Row

Case Else
End Select

ElseIf counter = 4 Or counter = 5 Or counter = 6 Then

Select Case Trim(cll.Value)

Case Is = "CANC"
rwn4 = cll.Row

Case Is = "NTU"
rwn5 = cll.Row

Case Is = "CANC+NTU"
rwn6 = cll.Row

Case Else
End Select

Else: End If
Else: End If

Next cll

' add rows into new row

'm

c = sht.UsedRange.Columns.Count

MsgBox c
MsgBox sht.Range(Cells(rwn, 3), Cells(rwn, c)).Address
MsgBox c

sht.Range(Cells(rwn, 3), Cells(rwn, c)).Copy
sht.Range(Cells(rwn3, 3), Cells(rwn3, c)).Paste


sht.Range(Cells(rwn2, 3), Cells(rwn2, c)).Copy
sht.Range(Cells(rwn3, 3), Cells(rwn3, c)).PasteSpecial operation:=xlAdd

'p

sht.Range(Cells(rwn4, 3), Cells(rwn4, c)).Copy
sht.Range(Cells(rwn6, 3), Cells(rwn6, c)).Paste


sht.Range(Cells(rwn5, 3), Cells(rwn5, c)).Copy
sht.Range(Cells(rwn6, 3), Cells(rwn6, c)).PasteSpecial operation:=xlAdd


Else: End If

Next sht

End Sub

"Per Jessen" wrote:

Hi

Nothing wrong with the line in question, but I think that the variable rwn
is empty, causing the error.

BTW: Please post the entire code, as it's eaysier to locate the error.

Regards,
Per

"PBcorn" skrev i meddelelsen
...
I have the following line of code* causing the above error:

sht.activate

*sht.Range(Cells(rwn, 3), Cells(rwn, sht.UsedRange.Columns.Count)).Copy

this is within a for-next loop:

For Each sht In ThisWorkbook.Worksheets
next sht

rwn is an integer from a line within a another for-next loop:

rwn = cll.row

why is this causing an error?



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Run Time error '1004': Application-defined or object-defined e

I just noticed, some trim() functions were missing, causing rwn to be 0. Now
however I am getting "object does not support this property or method" for
the paste line.

"PBcorn" wrote:


Full code below

the purpose of the macro is to insert a row above certain row labels (in col
2), add a new row label for this row, then add together two particualr
existing rows and paste into the new row. (using pastespecial add operation).
Note that the row labels are repeated once in each sheet.The data looks like:



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Run Time error '1004': Application-defined or object-defined error

Qualify the ranges:

sht.Range(sht.Cells(rwn, 3), sht.Cells(rwn, sht.UsedRange.Columns.Count)).Copy

or
with sht
'notice the leading dots!
.Range(.Cells(rwn, 3), .Cells(rwn, .UsedRange.Columns.Count)).Copy
end with

If the code is behind a worksheet, those unqualified ranges refer to the sheet
with the code.

If the code is in a general module, then those unqualified ranges refer to the
activesheet.


PBcorn wrote:

I have the following line of code* causing the above error:

sht.activate

*sht.Range(Cells(rwn, 3), Cells(rwn, sht.UsedRange.Columns.Count)).Copy

this is within a for-next loop:

For Each sht In ThisWorkbook.Worksheets
next sht

rwn is an integer from a line within a another for-next loop:

rwn = cll.row

why is this causing an error?


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Run Time error '1004': Application-defined or object-defined e

I have qualified these ranges but still get "object does not support this
property or method" on the paste line:

sht.Range(sht.Cells(rwn3, 3), sht.Cells(rwn3, c)).Paste

I have checked the paste range, it is the same size as the copied range.

"Dave Peterson" wrote:

Qualify the ranges:

sht.Range(sht.Cells(rwn, 3), sht.Cells(rwn, sht.UsedRange.Columns.Count)).Copy

or
with sht
'notice the leading dots!
.Range(.Cells(rwn, 3), .Cells(rwn, .UsedRange.Columns.Count)).Copy
end with

If the code is behind a worksheet, those unqualified ranges refer to the sheet
with the code.

If the code is in a general module, then those unqualified ranges refer to the
activesheet.


PBcorn wrote:

I have the following line of code* causing the above error:

sht.activate

*sht.Range(Cells(rwn, 3), Cells(rwn, sht.UsedRange.Columns.Count)).Copy

this is within a for-next loop:

For Each sht In ThisWorkbook.Worksheets
next sht

rwn is an integer from a line within a another for-next loop:

rwn = cll.row

why is this causing an error?


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Run Time error '1004': Application-defined or object-defined e

problem sorted - I replaced .Paste with .Pastespecial. VB Help implies that
the paste method does not apply to the range object, but Pastespecial does.
Strange.

"PBcorn" wrote:

I have qualified these ranges but still get "object does not support this
property or method" on the paste line:

sht.Range(sht.Cells(rwn3, 3), sht.Cells(rwn3, c)).Paste

I have checked the paste range, it is the same size as the copied range.

"Dave Peterson" wrote:

Qualify the ranges:

sht.Range(sht.Cells(rwn, 3), sht.Cells(rwn, sht.UsedRange.Columns.Count)).Copy

or
with sht
'notice the leading dots!
.Range(.Cells(rwn, 3), .Cells(rwn, .UsedRange.Columns.Count)).Copy
end with

If the code is behind a worksheet, those unqualified ranges refer to the sheet
with the code.

If the code is in a general module, then those unqualified ranges refer to the
activesheet.


PBcorn wrote:

I have the following line of code* causing the above error:

sht.activate

*sht.Range(Cells(rwn, 3), Cells(rwn, sht.UsedRange.Columns.Count)).Copy

this is within a for-next loop:

For Each sht In ThisWorkbook.Worksheets
next sht

rwn is an integer from a line within a another for-next loop:

rwn = cll.row

why is this causing an error?


--

Dave Peterson

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Run Time error '1004': Application-defined or object-defined e

How about:

sht.Range(sht.Cells(rwn, 3), sht.Cells(rwn, sht.UsedRange.Columns.Count)).Copy _
destination:=sht.Cells(rwn3, 3)



PBcorn wrote:

I have qualified these ranges but still get "object does not support this
property or method" on the paste line:

sht.Range(sht.Cells(rwn3, 3), sht.Cells(rwn3, c)).Paste

I have checked the paste range, it is the same size as the copied range.

"Dave Peterson" wrote:

Qualify the ranges:

sht.Range(sht.Cells(rwn, 3), sht.Cells(rwn, sht.UsedRange.Columns.Count)).Copy

or
with sht
'notice the leading dots!
.Range(.Cells(rwn, 3), .Cells(rwn, .UsedRange.Columns.Count)).Copy
end with

If the code is behind a worksheet, those unqualified ranges refer to the sheet
with the code.

If the code is in a general module, then those unqualified ranges refer to the
activesheet.


PBcorn wrote:

I have the following line of code* causing the above error:

sht.activate

*sht.Range(Cells(rwn, 3), Cells(rwn, sht.UsedRange.Columns.Count)).Copy

this is within a for-next loop:

For Each sht In ThisWorkbook.Worksheets
next sht

rwn is an integer from a line within a another for-next loop:

rwn = cll.row

why is this causing an error?


--

Dave Peterson


--

Dave Peterson
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
Export a chart in a GIF file. Run-time error '1004': Application-defined or object-defined error; [email protected] Excel Programming 4 September 16th 07 11:09 PM
Run-time error 1004. Application-defined or object-defined error Martin Brennan Excel Programming 2 June 7th 07 01:22 PM
Run Time Error 1004 - Application-defined or object-defined error brent Excel Programming 2 October 3rd 05 05:23 PM
Run-time Error 1004: Application-defined or Object-defined Error Adrian Excel Programming 6 August 23rd 05 06:28 AM
Macro Run-time Error 1004 Application Defined or Object Defined Error Anddmx Excel Programming 6 June 9th 04 03:40 PM


All times are GMT +1. The time now is 11:59 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"