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"
ABCD
11dfghdfhdfhdfhh
22 WBS ElementEstablishmentCost Element
33WBS 001Abercorn504307
44504401
55504402
66Result
77WBS 003Anderson504307
88504402
99Result
1010WBS 099Achcraig504126
1111504307
1212Result
1313WBS 102Balornock504122
1414504129
1515504307
1616504402
1717Result

<tbody>
</tbody>
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
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,215,968
Messages
6,127,983
Members
449,414
Latest member
sameri

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