Skip to content

Instantly share code, notes, and snippets.

@stevesohcot
Created July 31, 2021 04:03
Show Gist options
  • Select an option

  • Save stevesohcot/d6a0291ef0be60419b9e5f22f4c24e92 to your computer and use it in GitHub Desktop.

Select an option

Save stevesohcot/d6a0291ef0be60419b9e5f22f4c24e92 to your computer and use it in GitHub Desktop.
VBA - Remove rows with zero
Function removeRowsWithValueOfZero()
' Sort on the values (Col N)
' when it comes time to delete, it'll be much faster!
Range("A1").Select
ActiveWorkbook.Worksheets("data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("data").Sort.SortFields.Add2 Key:=Range("N:N"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("data").Sort
.SetRange Range("A:N")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' Format value to comma format
Columns("N:N").Select
Selection.Style = "Comma"
ActiveSheet.Range("A:N").AutoFilter Field:=14, Criteria1:="-"
' Delete where it's zero
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
' Remove AutoFilter
Selection.AutoFilter
Range("A1").Select
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment