VBA Copy Cells error 1004

Koala123

New Member
Joined
Apr 13, 2019
Messages
24
Office Version
  1. 365
Hi Pros, can anyone please help me with this?

I was using VBA to do some copy & paste, this time I got a error because the target range has no data/value, and gives me a run-time error 1004: No cells were found.

In most of time these cells have value, as it's pasted from a raw data sheet which is updated on a daily basis, therefore I still want to keep these lines, just wondering is there a code to skip this error so that this macro can keep running? Thanks heaps!

Code:
ws1.Select
ActiveSheet.Range("A1:G" & LROW).AutoFilter Field:=7, Criteria1:= _
        "NOVATED LEASE"


[B]Range("A3:G" & LROW).SpecialCells(xlCellTypeVisible).Copy[/B] ---> ERROR


Sheets("Novated").Select
Range("A4").Select
ActiveSheet.Paste

Any thoughts would be appreciated!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,

you could try with
Code:
On Error Resume Next
.
 
Upvote 0
You could check if there are visible rows like this:


Code:
Sub test()
  Dim ws1 As Worksheet, Lrow As Long, lr2 As Long
  Set ws1 = ActiveSheet
  ws1.Select
  If ws1.AutoFilterMode Then ws1.AutoFilterMode = False
  Lrow = ws1.Range("G" & Rows.Count).End(xlUp).Row
  ws1.Range("A1:G" & Lrow).AutoFilter Field:=7, Criteria1:="NOVATED LEASE"
  lr2 = ws1.Range("G" & Rows.Count).End(xlUp).Row
  If lr2 < 3 Then
    MsgBox "No data"
  Else
    ws1.Range("A3:G" & Lrow).SpecialCells(xlCellTypeVisible).Copy Sheets("Novated").Range("A4")
  End If
End Sub
 
Upvote 0
You could check if there are visible rows like this:


Code:
Sub test()
  Dim ws1 As Worksheet, Lrow As Long, lr2 As Long
  Set ws1 = ActiveSheet
  ws1.Select
  If ws1.AutoFilterMode Then ws1.AutoFilterMode = False
  Lrow = ws1.Range("G" & Rows.Count).End(xlUp).Row
  ws1.Range("A1:G" & Lrow).AutoFilter Field:=7, Criteria1:="NOVATED LEASE"
  lr2 = ws1.Range("G" & Rows.Count).End(xlUp).Row
  If lr2 < 3 Then
    MsgBox "No data"
  Else
    ws1.Range("A3:G" & Lrow).SpecialCells(xlCellTypeVisible).Copy Sheets("Novated").Range("A4")
  End If
End Sub

Thank you so much, I have fixed it!
 
Upvote 0
Glad to help you and thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,993
Members
448,539
Latest member
alex78

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