Last active
May 1, 2017 17:44
-
-
Save HerbFargus/e400384d5a47689ba36c4976965b1669 to your computer and use it in GitHub Desktop.
VBA (Excel): Check if a cell is empty, if so, delete the entire row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Excel VBA Macro: This checks if a cell is empty or blank, if so then it will delete the row. | |
Sub Main() | |
With Application ' Optimise so deleting rows doesnt hang | |
.ScreenUpdating = False | |
.Calculation = xlCalculationManual | |
End With | |
' Set up prompt input boxes for user to choose the columns | |
Column1 = InputBox("Choose the column with empty cells...") | |
If Column1 = "" Or DelimitedColumn1 Like "*[!A-Za-z]*" Then Exit Sub | |
LastRow = Range("A" & Rows.Count).End(xlUp).Row ' finding last row used | |
For i = LastRow To 1 Step -1 ' iterating from last row to 1st | |
If IsEmpty(Range(Column1 & i).Value) Then Rows(i).EntireRow.Delete ' Check if Column is empty, if so delete the row | |
If Range(Column1 & i) = vbNullString Then Rows(i).EntireRow.Delete ' Check if Column 1 is a null string (""), if so delete the row | |
Next | |
With Application | |
.ScreenUpdating = True | |
.Calculation = xlCalculationAutomatic | |
.CutCopyMode = False | |
End With | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment