Excel Run-Time Error 1004 No cells were found

Add365

New Member
Joined
Jun 12, 2021
Messages
35
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I know this has been asked before but I cant work out from looking at previous threads how to fix my issue.
I am running a stock take macro where I am copying data from an invoice over to a stock out list but in one column I want it to fill in the blank cells with the data above. If I run the macro with 2 rows of data coming accross it comes up Run-time error 1004 no cells was found, but the macro has actually worked and I have to click end. If I run the macro with say 3 or 4 rows of data coming accross it works fine and no errors.
I have tried putting On Error Resume Next & On Error GoTo 0 but then this just skips the code and the macro dosent work properley.

Please can you help me out, below is my vba code and thank you for your support & help.

Dim lr As Long
Sheets("Invoice").Select
Range("C6").Select
Selection.Copy
Sheets("Stock Out").Select
lr = Range("A" & Rows.Count).End(xlUp).Row

Range("A1:A" & lr).SpecialCells(xlCellTypeBlanks).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 
See if this does what you want:

VBA Code:
    If Sheets("Stock Out").Application.WorksheetFunction.CountBlank(Sheets("Stock Out").Range("A1:A" & lr)) > 0 Then    ' Blank cell found in range
        Range("A1:A" & lr).SpecialCells(xlCellTypeBlanks).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False ' ERROR No cells found
    End If

That should handle 'no blank cells found'.
Brilliant yes this has worked, no errors anymore. Thanks so much for your help :)
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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