Excel

TheSmallman.com

an XL ideas Lab

Dashboards VBA
  • Home
  • Dashboards
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
    • Power Pivot a User Guide
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About
Menu

Excel Dashboards VBA

Street Address
City, State, Zip
Phone Number
an XL ideas Lab

Your Custom Text Here

Excel Dashboards VBA

  • Home
  • Dashboards
  • Excel Tips
    • Tips & Tricks
    • Charts
    • Modelling
    • Infographics
    • VBA
  • Shop Dashboards
  • PowerPivot
    • Power Pivot a User Guide
  • Courses
    • Excel Dashboard Course
    • Advanced Dashboard Course
    • Financial Modelling Course
    • Excel VBA Course
  • Blog
  • About

Delete Blank and Zero Value Cells from Columns

January 3, 2018 Marcus Small
Photo by Samuel Zeller on Unsplash

Photo by Samuel Zeller on Unsplash

Have you ever wanted to test a group of columns for null or zero value cells and if there is nothing in that group of columns then delete the entire row.  I came across this problem with a worksheet I was working on recently and used my well-worn and trusted autofilter to remove those unwanted columns.  This was done with the assistance of a formula.  To get over the line I needed a sumproduct.

 

=SUMPRODUCT((LEN(B2:N2)>0)*(B2:N2<>0))

 

Using the above formula in code should work nicely.  Just set the range and assign the formula to the range.  It will check the columns from B to N for both blanks and zeros.  If there is data in the cells with values then a 1 will appear in the helper column we are creating.  Otherwise there will be a zero.  The following is the code which manages to achieve the task.  It is using column 15 or Column O as the helper column.  The formula is pushed into column O from row 2 to the last used row and then those cells which are equal to zero are deleted in one swift movement with the aid of the autofilter.  After this is done the entire column is deleted. 

 

Option Explicit

Sub DelBlankRow()
Dimrng As Range

Set rng = Range(Cells(1, 15), Cells([a1].CurrentRegion.Rows.Count, 15))
      rng.Offset(1) = "=SUMPRODUCT((LEN(B2:N2)>0)*(B2:N2<>0))"
      rng.AutoFilter 1, 0
      rng.Offset(1).EntireRow.Delete
      rng.EntireColumn.Delete
End Sub

 

Setting up the range is key at the start.  It will help as the range is required to be called upon many times.  The attached file is an example of the process which will remove a row of blank and/or zero values.  It is fast and easy to use.

 

CheckZero.xlsm

← Find Closest Match in ExcelMake Excel Speak →

Featured Posts

Excel Dashboards: Tracking a Crisis

Excel Dashboards: Tracking a Crisis
April 14, 2020

Recent Posts

Populating an Excel Table from a Range of Cells with VBA

Populating an Excel Table from a Range of Cells with VBA June 12, 2025

Fuzzy Distribution with Randbetween

Fuzzy Distribution with Randbetween May 21, 2025

Add Minimum and Maximum for Chart in Cells

Add Minimum and Maximum for Chart in Cells March 12, 2025

Inflation Over Multiple Years in a Single Cell

Inflation Over Multiple Years in a Single Cell January 10, 2025

Hubspot Dashboard

Hubspot Dashboard October 3, 2024

Monthly Dashboard With Supporting Metrics

Monthly Dashboard With Supporting Metrics September 25, 2024

Excel Show Missing Sheet Tabs

Excel Show Missing Sheet Tabs July 29, 2024

Run Macro Overnight Automatically

Run Macro Overnight Automatically June 24, 2024

Split File into Parts and Save to Directory

Split File into Parts and Save to Directory April 20, 2024

Most Popular Author

Most Popular Author December 14, 2023

 

Follow US:

 
 

MarcusSmall@thesmallman.com

 

TheSmallman.com - Making your small systems hum...
© Copyright 2013-2024 theSmallman.com All Rights Reserved.