VBA - finding and deleting specific cells

Puppies72

Board Regular
Joined
Mar 29, 2010
Messages
211
Hi all,

I have a macro that imports data from several sheets into a master sheet however I need to clear certain data from the master sheet prior to the import.

I need a bit of code that will do the following:

Search K4:K10003 for any cells where the value = 16 , once a cell is found then clear that cells' contents and the contents of the cell to the left, then find the next one and repeat

I don't want the cells deleted just the contents cleared.

As always help greatly appreciated
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Perhaps something like

Code:
Sub delete_sixteens()

Dim i As Integer
    Range("K4").Select
 For i = 1 To Selection.CurrentRegion.Rows.Count - 1
    If ActiveCell.Value = 16 Then
        ActiveCell.ClearContents
        ActiveCell.Offset(0, -1).ClearContents
        ActiveCell.Offset(1, 0).Select
    Else: ActiveCell.Offset(1, 0).Select
    End If
 Next i
End Sub

might be of use. To edit you could always replace 16 with a variable that is dependent on a cell's value (for example) as per your needs. Similarly I've assumed all rows between 4 and 10003 are filled but if not you can substitute the loop accordingly.

HTH
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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