Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Error with code that paste on next available row

The second bottom half of this code is supposed to paste the range to
the sheet "data" (A:F) on the next available row.

It worked once somehow but, I can't get past the error on this line
now.

Range(cell, Cells(cell.Row, "g")).Copy sh.Cells(NewRow, 1)


Sub ABC2()
Dim cell As Range, c As Range
Dim i As Range, rw As Long
Dim sh As Worksheet
With Worksheets("List")
Set c = .Range(.Cells(6, "B"), .Cells(6, "B").End(xlDown))
Set i = .Range(.Cells(6, "I"), .Cells(6, "I").End(xlDown))
End With


Set sh = Worksheets("Data")
LastRow = sh.Cells(Rows.Count, "a").End(xlUp).Row
NewRow = LastRow + 1
For Each cell In c
If Application.CountIf(i, cell) 0 Then
Range(cell, Cells(cell.Row, "g")).Copy sh.Cells(NewRow, 1)
NewRow = NewRow + 1
End If
Next
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default Error with code that paste on next available row

On Mar 11, 9:53*am, "J.W. Aldridge"
wrote:
The second bottom half of this code is supposed to paste the range to
the sheet "data" (A:F) on the next available row.

It worked once somehow but, I can't get past the error on this line
now.

Range(cell, Cells(cell.Row, "g")).Copy sh.Cells(NewRow, 1)

Sub ABC2()
Dim cell As Range, c As Range
Dim i As Range, rw As Long
Dim sh As Worksheet
With Worksheets("List")
Set c = .Range(.Cells(6, "B"), .Cells(6, "B").End(xlDown))
Set i = .Range(.Cells(6, "I"), .Cells(6, "I").End(xlDown))
End With

Set sh = Worksheets("Data")
LastRow = sh.Cells(Rows.Count, "a").End(xlUp).Row
NewRow = LastRow + 1
For Each cell In c
If Application.CountIf(i, cell) 0 Then
* * Range(cell, Cells(cell.Row, "g")).Copy sh.Cells(NewRow, 1)
* * NewRow = NewRow + 1
End If
Next
End Sub


There is only one way I can think of that would throw an error with
the code you listed. This would be that the worksheet that you are
copying to has no more room to accommodate the copy (i.e. you exceed
the row size limit for the worksheet). Otherwise, please provide the
error that is occurring and the context in which the error is
occurring. You may want to step through your code to see how it
operates and to see "where" your error is occurring. You can do this
by pressing the F8 key multiple times.

Matt Herbert
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Error with code that paste on next available row

Run-time error '1004';
Method 'Range' of object'_Global' failed

I ran through the code as suggested...

Just as I reached the next line, I got the error message above.

Range(cell, Cells(cell.Row, "g")).Copy sh.Cells(NewRow, 1)
NewRow = NewRow + 1

I am only at line 3197 so I have plenty of room left. The rest of the
worksheet below and to the right is empty.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Error with code that paste on next available row

Did you look at my last response? I moved the With statement to include the
line you have in error and then added two periods so the sheet "List" is
referenced in the statement.

"J.W. Aldridge" wrote:

Run-time error '1004';
Method 'Range' of object'_Global' failed

I ran through the code as suggested...

Just as I reached the next line, I got the error message above.

Range(cell, Cells(cell.Row, "g")).Copy sh.Cells(NewRow, 1)
NewRow = NewRow + 1

I am only at line 3197 so I have plenty of room left. The rest of the
worksheet below and to the right is empty.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Error with code that paste on next available row

I think your problem is occuring because you aren't specifying a worksheet.
try this

Sub ABC2()
Dim cell As Range, c As Range
Dim i As Range, rw As Long
Dim sh As Worksheet

Set sh = Worksheets("Data")
LastRow = sh.Cells(Rows.Count, "a").End(xlUp).Row
NewRow = LastRow + 1

With Worksheets("List")
Set c = .Range(.Cells(6, "B"), .Cells(6, "B").End(xlDown))
Set i = .Range(.Cells(6, "I"), .Cells(6, "I").End(xlDown))

For Each cell In c
If Application.CountIf(i, cell) 0 Then
.Range(cell, .Cells(cell.Row, "G")).Copy sh.Cells(NewRow, "A")
NewRow = NewRow + 1
End If
Next
End With

End Sub


"J.W. Aldridge" wrote:

The second bottom half of this code is supposed to paste the range to
the sheet "data" (A:F) on the next available row.

It worked once somehow but, I can't get past the error on this line
now.

Range(cell, Cells(cell.Row, "g")).Copy sh.Cells(NewRow, 1)


Sub ABC2()
Dim cell As Range, c As Range
Dim i As Range, rw As Long
Dim sh As Worksheet
With Worksheets("List")
Set c = .Range(.Cells(6, "B"), .Cells(6, "B").End(xlDown))
Set i = .Range(.Cells(6, "I"), .Cells(6, "I").End(xlDown))
End With


Set sh = Worksheets("Data")
LastRow = sh.Cells(Rows.Count, "a").End(xlUp).Row
NewRow = LastRow + 1
For Each cell In c
If Application.CountIf(i, cell) 0 Then
Range(cell, Cells(cell.Row, "g")).Copy sh.Cells(NewRow, 1)
NewRow = NewRow + 1
End If
Next
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
VBA code does not copy and paste to next row for each zip code Miguel Excel Programming 5 November 14th 08 03:13 PM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Cut and Paste using Macro gives paste special method error Lourens Pentz Excel Programming 3 November 21st 04 10:42 PM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


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