Delete item from list and remove the resulting blank cell

hambone

New Member
Joined
Oct 30, 2008
Messages
7
I need a macro that will look at a range of values (e.g. G3:G200) and delete the value that matches the value in cell G2. I then want the macro to delete the empty cell by shifting all cells in the range up one.

All this action needs to only happen in column G. I don't need any other data deleted.

TIA!!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Like this maybe
Code:
Sub delrows()
    For I = 200 To 3 Step -1
        If Cells(I, "G").Value = Cells(2, "G").Value Then
            With Cells(I, "G")
                .Select
                .Value = ""
                Selection.Delete Shift:=xlUp
            End With
        End If
    Next I
End Sub
 
Upvote 0
Looks like it's going to work great.

What if I wanted to also delete the cell values in columns F & H (the ones right next to "G") and shift all three columns up. Everything else is the same meaning Io want to delete those three cells based on a match in G2 & the range G3:G200
 
Upvote 0
Code:
Sub delrows()
    For I = 20 To 3 Step -1
        If Cells(I, "G").Value = Cells(1, "G").Value Then
            With Range(Cells(I, "F"), Cells(I, "H"))
                .Select
                .Value = ""
                Selection.Delete Shift:=xlUp
            End With
        End If
    Next I
End Sub
 
Upvote 0
Possibly another option....

Code:
Sub Macro2()
    Dim X As Range
    Application.ScreenUpdating = False
    
    With Range("G1:G" & Range("G" & Rows.Count).End(xlUp).Row)
        .AutoFilter Field:=1, Criteria1:=Range("G1").Value
        Set X = .Offset(1, -1).Resize(.Rows.Count - 1, 3).SpecialCells(xlCellTypeVisible)
        ActiveSheet.AutoFilterMode = False
        X.Delete
    End With
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,544
Messages
6,056,027
Members
444,840
Latest member
RazzelDazel

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