Runtime 1004 Copy Cells

silentwolf

Well-known Member
Joined
May 14, 2008
Messages
1,216
Office Version
  1. 2016
Hi guys,
hope someone can look over my code and let me know what's wrong with this code.

Code:
Sub CopyNonBlankData()
    Dim wkbThis As Workbook
    Dim lngERow As Long
    Dim lngLRow As Long
    Dim i As Integer
    
    Set wkbThis = ActiveWorkbook
    
    lngLRow = tabWeeklyPlaner.Cells(Rows.Count, 1).End(xlUp).Row
    
    With ThisWorkbook
        For i = 3 To lngLRow
            If tabWeeklyPlaner.Cells(i, 1) <> "" Then
                tabWeeklyPlaner.Range(Cells(i, 1)).Copy
                tabWeeklyObjects.Activate
                lngERow = tabWeeklyObjects.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
                ActiveSheet.Paste Destination:=tabWeeklyObjects.Range(Cells(lngERow, 1))
                tabWeeklyPlaner.Activate
            End If
        Next i
    End With
    Application.CutCopyMode = False
    
End Sub

The issue I am getting an Runtime Error on Line "tabWeeklyPlaner.range(Cells(i,1).copy"

tabWeeklyPlaner and tabWeeklyObjects are the Codenames of the Worksheets.

Also I as the tabWeeklyPlaner has in the range of Cells blanks and a Summery on the last used Cell.

I like to copy all not blank cells and without Summery into tabWeeklyObjects.

Can someone give me a hand on this please.

Thanks

Albert
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Another Bug
Code:
 ActiveSheet.Paste Destination:=tabWeeklyObjects.Range(Cells(lng[COLOR=#ff0000]L[/COLOR]Row, 1))

Code:
[COLOR=#333333]Sheets("tabWeeklyPlaner").....[/COLOR]
 
Last edited:
Upvote 0
Hi guys,

Thanks for your reply!
jkpieterse yes you are right!

Code:
Sub CopyNonBlankData()
    Dim wkbThis As Workbook
    Dim lngERow As Long
    Dim lngLRow As Long
    Dim i As Integer
    
    Set wkbThis = ActiveWorkbook
    
    lngLRow = tabWeeklyPlaner.Cells(Rows.Count, 1).End(xlUp).Row
    
    With ThisWorkbook
        For i = 3 To lngLRow
            If tabWeeklyPlaner.Cells(i, 1) <> "" Then
                tabWeeklyPlaner.Cells(i, 1).Copy
                lngERow = tabWeeklyObjects.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
                
                ActiveSheet.Paste Destination:=tabWeeklyObjects.Cells(lngERow, 1)
                
                tabWeeklyPlaner.Activate
            End If
        Next i
    End With
    Application.CutCopyMode = False
    
End Sub

I also don't need to activate line either.. however there is still the problem with the "Summery"
Code:
            If tabWeeklyPlaner.Cells(i, 1) <> "" OR "Summery" Then

does someone know how to chang that line?

Cheers..
 
Upvote 0
Maybe...
Code:
If tabWeeklyPlaner.Cells(i, 1) <> "" Or tabWeeklyPlaner.Cells(i, 1) <>"Summery" Then

Also make sure "Summery" shouldn't be spelt "Summary"
 
Upvote 0
Hi Mark858,

unfortunatelly not :(

Well if I can not get it to work I am just delete the "Summary" oh just see it I did spell it wrong in my thread :) "Summery" should be "Summary" oops...

But you get what I mean at leas ,)
 
Upvote 0
Hi Mark,

Yes I did see my mistake with spelling :)

Here is now my modified code..

It works .-)

Code:
Sub CopyNonBlankData()
    Dim wkbThis As Workbook
    Dim lngERow As Long
    Dim lngLRow As Long
    Dim i As Integer
    
    Set wkbThis = ActiveWorkbook
    
    Application.ScreenUpdating = False
    
    lngLRow = tabWeeklyPlaner.Cells(Rows.Count, 1).End(xlUp).Row
    
    
    With ThisWorkbook
        For i = 3 To lngLRow
            If tabWeeklyPlaner.Cells(i, 1) <> "" And tabWeeklyPlaner.Cells(i, 1) <> "Ergebnis" Then
                tabWeeklyPlaner.Cells(i, 1).Copy
                lngERow = tabWeeklyObjects.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
                
                ActiveSheet.Paste Destination:=tabWeeklyObjects.Cells(lngERow, 1)
            End If
        Next i
    End With
    Application.CutCopyMode = False
    tabWeeklyPlaner.Activate
    
    Application.ScreenUpdating = True
End Sub

It runs smoothly now :)

Cheers for all you guys input :)
 
Upvote 0

Forum statistics

Threads
1,215,248
Messages
6,123,873
Members
449,130
Latest member
lolasmith

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top