VBA/Macros - How to auto delete data from cell if cell begins with

egarcia

New Member
Joined
May 8, 2014
Messages
2
I would like to see if someone can help me with a macros formula. I need to delete cell values if a cell begins with a certain number.

Delete all cell values for B22 through D65536 IF cell in C22 through C65536 begins with 3.00, 4.00, 5.00 AND Delete all cell values for G22 through I65536 IF cell in H22 through H65536 begins with 3.00, 4.00, 5.00
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Here is one way:
Code:
Sub delStuff()
Dim sh As Worksheet, lr As Long
Set sh = Sheets(1) 'Edit sheet name
lr = sh.Cells.Find("*", sh.Range("A1"), xlFormulas, xlPart, xlByRows, xlPrevious).Row
    For i = lr To 22 Step -1
        With sh
            If Left(Trim(.Cells(i, 3).Value), 4) = CDbl("3.00") Or Left(Trim(.Cells(i, 3).Value), 4) = CDbl("4.00") Or _
            Left(Trim(.Cells(i, 3).Value), 4) = CDbl("5.00") Then
                .Cells(i, 2).Resize(1, 3).ClearContents
            End If
            If Left(Trim(.Cells(i, 8).Value), 4) = CDbl("3.00") Or Left(Trim(.Cells(i, 8).Value), 4) = CDbl("4.00") Or _
            Left(Trim(.Cells(i, 8).Value), 4) = CDbl("5.00") Then
                .Cells(i, 7).Resize(1, 3).ClearContents
            End If
        End With
    Next
End Sub
If your values in the columns to be cleared are derived from formulas, this will remove your formulas. Also, this assumes the cells contain data type numbers in columns C and G.
 
Last edited:
Upvote 0
thanks, this worked!


Here is one way:
Code:
Sub delStuff()
Dim sh As Worksheet, lr As Long
Set sh = Sheets(1) 'Edit sheet name
lr = sh.Cells.Find("*", sh.Range("A1"), xlFormulas, xlPart, xlByRows, xlPrevious).Row
    For i = lr To 22 Step -1
        With sh
            If Left(Trim(.Cells(i, 3).Value), 4) = CDbl("3.00") Or Left(Trim(.Cells(i, 3).Value), 4) = CDbl("4.00") Or _
            Left(Trim(.Cells(i, 3).Value), 4) = CDbl("5.00") Then
                .Cells(i, 2).Resize(1, 3).ClearContents
            End If
            If Left(Trim(.Cells(i, 8).Value), 4) = CDbl("3.00") Or Left(Trim(.Cells(i, 8).Value), 4) = CDbl("4.00") Or _
            Left(Trim(.Cells(i, 8).Value), 4) = CDbl("5.00") Then
                .Cells(i, 7).Resize(1, 3).ClearContents
            End If
        End With
    Next
End Sub
If your values in the columns to be cleared are derived from formulas, this will remove your formulas. Also, this assumes the cells contain data type numbers in columns C and G.
 
Upvote 0

Forum statistics

Threads
1,226,693
Messages
6,192,471
Members
453,726
Latest member
JoeH57

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