Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8307459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:31:41+00:00 2026-06-08T18:31:41+00:00

I have written a macro to find blank cells from a certain range using

  • 0

I have written a macro to find blank cells from a certain range using SpecialCells method of excel range object.
When i am trying to execute following code i get a exception as “No cells found”.

Sub test()
Debug.Print Sheet1.Range("A1:D4").SpecialCells(xlCellTypeBlanks).Address
End Sub

Steps:-

  1. Open a new Excel instance.
  2. Press ALT + F11/ Open VBE
  3. Insert a new Module
  4. Paste the above code and run test macro as specified above.

Output Received:

Runtime Error ‘1004’. No Cells Found.

Output Expected:

$A$1:$D$4

Case 1:

Now if i do any operation of cell A1. Operation such as giving fill color, etc. Call the test() macro then it does not throw exception.

Output Received:

$A$1

Output Expected:

$A$1:$D$4

Case 2:

Suppose if i give any value in cell B3. Call the test() macro, exception is not thrown.

Output Received:

$B$1:$B$2,$A$1:$A$3

Output Expected:

$A$1:$D$4

Case 3:

If i try to edit value or fill the cell outside the range “A1:D4” for example E10 and execute test() method then it gives me the proper output.

Output Received:

$A$1:$D$4

Note: Execute each Case with a new excel instance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:31:43+00:00Added an answer on June 8, 2026 at 6:31 pm

    The reason is SpecialCells “looks” at the UsedRange when returning a range.

    So using SpecialCells on an unused sheet will return Runtime Error '1004'. No Cells Found. (As an aside always use error handling with SpecialCells)

    When you change cell A1, that becomes the sheets UsedRange, hence your Case 1 return of “A1”

    The code below looks to return Range(“A1:D4”).SpecialCells(xlCellTypeBlanks) for

    1. A blank sheet – fails
    2. The sheet with A10 filled in – A1:A4
    3. The sheet with A10 cleared – A1:A4
    4. The sheet with the usedrange reset (which is effectively 1) – fails

      Sub Test()
      Dim ws As Worksheet
      Set ws = Sheets.Add
      On Error Resume Next
      'blank sheet
      Debug.Print "Blank sheet " & ws.Range("A1:D4").SpecialCells(xlCellTypeBlanks).Address
      'enter in A10
      ws.[a10] = "test"
      Debug.Print "With A10 " & ws.Range("A1:D4").SpecialCells(xlCellTypeBlanks).Address
      'clear a10
      ws.[a10].ClearContents
      Debug.Print "With A10 cleared " & ws.Range("A1:D4").SpecialCells(xlCellTypeBlanks).Address
      'reset range
      ActiveSheet.UsedRange
      Debug.Print "With A10 cleared and range reset" & ws.Range("A1:D4").SpecialCells(xlCellTypeBlanks).Address
      On Error GoTo 0
      End Sub
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a macro to dump excel cells on to a notepad file.
I have written an Excel VBA macro which imports data from a HTML file
I have written a VBA macro in an excel spreadsheet that opens all workbooks
I have written this code inside a servlet to delete certain records from three
I have written a macro in excel 2007 to log water-level readings. Once logged,
I have recently written a macro for visual studio 2010 in the macro IDE,
have written this little class, which generates a UUID every time an object of
I have written a function that extract the domain from hostname. e.g. www.domain.com ->
I have written function (actually a macro, but whatever) that works similarly to progn
I'm trying to debug and resolve some issues with a Win32 macro application written

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.