VBA for deleting cells

kd123

New Member
Joined
Oct 3, 2019
Messages
4
Hello,

I am looking for a VBA code that will delete all cells with a value less than 0.01 and shift cells up for column A and then to repeat the process for column C.

Thank you in advance for the help. I really appreciate it.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Code:
Option Explicit


Sub DelAC()
    Dim rng As Range, rng2 As Range, c As Range
    Dim lrA As Long, lrC As Long
    lrA = Range("A" & Rows.Count).End(xlUp).Row
    lrC = Range("C" & Rows.Count).End(xlUp).Row
    Set rng = Range("A1:A" & lrA)
    Set rng2 = Range("C1:C" & lrC)
    Application.ScreenUpdating = False
    For Each c In rng
        If c < 0.01 Then
            c.Delete
        End If
    Next c
    For Each c In rng2
        If c < 0.01 Then
            c.Delete
        End If
    Next c
    Application.ScreenUpdating = True
    MsgBox "complete"
End Sub
 
Upvote 0
Maybe

Rich (BB code):
Sub kd_123()
   With Range("A2", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate("if(" & .Address & "<0.01,true," & .Address & ")")
      On Error Resume Next
      .SpecialCells(xlConstants, xlLogical).Delete xlUp
      On Error GoTo 0
   End With
   With Range("C2", Range("C" & Rows.Count).End(xlUp))
      .Value = Evaluate("if(" & .Address & "<0.01,true," & .Address & ")")
      On Error Resume Next
      .SpecialCells(xlConstants, xlLogical).Delete xlUp
      On Error GoTo 0
   End With
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,217
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top