Simple Method to Select All Non-blank Cells in an Excel Worksheet

Simple Method to Select All Non-blank Cells in an Excel Worksheet




  1. First off, get access to Excel VBA editor using Alt + F11
  2. Then, put the following code into an unused module.
Sub SelectAllNonBlankCells()
    Dim objUsedRange As Range
    Dim objRange As Range
    Dim objNonblankRange As Range

    Set objUsedRange = Application.ActiveSheet.UsedRange

    For Each objRange In objUsedRange
        If Not (objRange.Value = "") Then
           If objNonblankRange Is Nothing Then
              Set objNonblankRange = objRange
           Else
              Set objNonblankRange = Application.Union(objNonblankRange, objRange)
           End If
        End If
    Next

    If Not (objNonblankRange Is Nothing) Then
       objNonblankRange.Select
    End If
End Sub


  1. After that, exit the VBA editor and add this macro to Quick Access Toolbar.
  2. Now, open your desired worksheet and click the macro button.
  3. At once, all non-blank cells will be selected, as shown in the following image.


For Any Query or help please comment or mail me on Gauravj75@gmail.com

Comments

Popular posts from this blog

GSTIN CheckSum Digit Logic

Spell-Number in Rupees Excel VBA Formula

Convert Number to Words Currency in MS Word