Delete just cells and shift up instead of delete entire row

piguy

New Member
Joined
Aug 26, 2011
Messages
32
OK here's my dilemna. I can delete the row if my condition is met (Columns C = "Gone"), but I need to instead make a selection and delete just those cells and shift up.
Basically if cell C in a row = Gone, then offset (-2, 12) as selected cells,
then delete shiftup.

I've gotten close to making this work if I start with a range and name the range of cells in the sheet, but they insert rows throughout the day, so the range is dynamic.

Code is shown below with deleting the row instead of selecting cells and deleting those specific ones and shifting up.

Thanks in advance!!!!

Code:
Sub DeleteRowsC()
    Dim Firstrow As Long
    Dim Lastrow As Long
    Dim Lrow As Long
    Dim CalcMode As Long
    Dim ViewMode As Long
    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
    End With
    
    'Selects sheet to use
    With Sheets("Today Sched")
        'select the sheet so can change the window view
        .Select
        'If you are in Page Break Preview Or Page Layout view go
        'back to normal view
        ViewMode = ActiveWindow.View
        ActiveWindow.View = xlNormalView
        'Turn off Page Breaks
        .DisplayPageBreaks = False
        'Set the second and last row to loop through
        Firstrow = 2
        Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
        'We loop from Lastrow to Firstrow (bottom to top)
        For Lrow = Lastrow To Firstrow Step -1
            'Check the values in the C column
            With .Cells(Lrow, "C")
                If Not IsError(.Value) Then
                    If .Value = "Gone" Then .EntireRow.delete
                    
                    'This will delete each row with the Value "Gone"
                    'in Column C, case sensitive.
                End If
            End With
        Next Lrow
    End With
    ActiveWindow.View = ViewMode
    With Application
        .ScreenUpdating = True
        .Calculation = CalcMode
    End With
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try

Code:
If .Value = "Gone" Then .Offset(-2, 12).Delete shift:=xlShiftUp
 
Upvote 0
Thanks guys! I got it to work by offsetting and then resizing to the selected area. Awesome response time! Thanks again!

Code:
 If .Value = "Gone" Then .Offset(, -2).Resize(2, 15).delete shift:=xlShiftUp
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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