Excel Run error - No Cells were found!

Phil Payne

Board Regular
Joined
May 17, 2013
Messages
131
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a worksheet which is an output from a database. (Example below)
I need to populate the empty cells in columns B and C with the data in the cells immediately above and the code I have (also below) works well if run in isolation.
However I have now combined this code with other code into one macro and I receive an error (Debug) message "No cells were found" on line 3 'selection.specialcells'.

Is there a way to avoid this? I cannot work out how to specify the last row of the range, as the number of rows will change (increase) over time.

Can anyone assist please?

Thanks in anticipation.

Code:
'MsgBox "Fill empty cells in columns B C with entry above"
    Range("a3:d3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.FormulaR1C1 = "=R[-1]C"
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD]dfgh[/TD]
[TD]dfhdfh[/TD]
[TD]dfhh[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]2[/TD]
[TD] WBS Element[/TD]
[TD]Establishment[/TD]
[TD]Cost Element[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]3[/TD]
[TD]WBS 001[/TD]
[TD]Abercorn[/TD]
[TD]504307[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]4[/TD]
[TD][/TD]
[TD][/TD]
[TD]504401[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]5[/TD]
[TD][/TD]
[TD][/TD]
[TD]504402[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]6[/TD]
[TD][/TD]
[TD][/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]7[/TD]
[TD]WBS 003[/TD]
[TD]Anderson[/TD]
[TD]504307[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]8[/TD]
[TD][/TD]
[TD][/TD]
[TD]504402[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]9[/TD]
[TD][/TD]
[TD][/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]10[/TD]
[TD]WBS 099[/TD]
[TD]Achcraig[/TD]
[TD]504126[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]11[/TD]
[TD][/TD]
[TD][/TD]
[TD]504307[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]12[/TD]
[TD][/TD]
[TD][/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]13[/TD]
[TD]WBS 102[/TD]
[TD]Balornock[/TD]
[TD]504122[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]14[/TD]
[TD][/TD]
[TD][/TD]
[TD]504129[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]15[/TD]
[TD][/TD]
[TD][/TD]
[TD]504307[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]16[/TD]
[TD][/TD]
[TD][/TD]
[TD]504402[/TD]
[/TR]
[TR]
[TD]17[/TD]
[TD]17[/TD]
[TD][/TD]
[TD][/TD]
[TD]Result[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try

Code:
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("B3:C" & LR).SpecialCells(xlCellTypeBlanks)
    .FormulaR1C1 = "=R[-1]C"
End With
 
Upvote 0
Try

Code:
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("B3:C" & LR).SpecialCells(xlCellTypeBlanks)
    .FormulaR1C1 = "=R[-1]C"
End With

HelloVoG

Thanks for the prompt response. Unfortunately the same error occurs.
Perhaps there a way to trap this with If/Then/Else statements. I'm trying that but can't seem to get it!
Regards,
 
Upvote 0
Sounds like your "blanks" are not actually blank. This should avoid the error but may not actually do anything

Code:
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
On Error Resume Next
With Range("B3:C" & LR).SpecialCells(xlCellTypeBlanks)
    .FormulaR1C1 = "=R[-1]C"
End With
On Error GoTo 0
 
Upvote 0
Hello again VoG

I just tried to use on error resume next and it gave rise to other problems. So I removed it and run my macro (with your code) again and, believe it or not, it worked.
I must have 'corrected' something when I removed the 'On Error Resume Next'

I will be trying to break this by running it a few times.

Thanks for your help.
 
Upvote 0
Thanks VoG

I have incorporated your latest with the on error codes and have run with no problems.

When I input On Error Resume Next I did not have On Error goto 0.

Cheers.

Sounds like your "blanks" are not actually blank. This should avoid the error but may not actually do anything

Code:
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
On Error Resume Next
With Range("B3:C" & LR).SpecialCells(xlCellTypeBlanks)
    .FormulaR1C1 = "=R[-1]C"
End With
On Error GoTo 0
 
Upvote 0
Team,

When I tried this to change the formulae to values, range B16:C17 displayed #N/A:

Rich (BB code):
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("B1:C" & LR).SpecialCells(xlCellTypeBlanks)
  .FormulaR1C1 = "=R[-1]C"
  .Value = .Value
End With
End Sub


The following update to the code gets rid of the #N/A's:

Rich (BB code):
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("B1:C" & LR)
  With .SpecialCells(xlCellTypeBlanks)
    .FormulaR1C1 = "=R[-1]C"
  End With
  .Value = .Value
End With
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,109
Members
452,302
Latest member
TaMere

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