VBA Delete Shift:=xlUp Alternative (Looking For A Different Method That Doesn't Destroy Formatting)

figuare9

Board Regular
Joined
Oct 23, 2017
Messages
118
This is a snippet of what I have, but I'm looking for another method that won't ruin formatting on a table.

Code:
Dim es As Worksheet, WSC As Worksheet
Set es = Worksheets("Master Employee List")
Set WSC = Worksheets("Testme")


r = Application.Match(emp, es.Range("A:A"), 0)
es.Rows(r).Delete Shift:=xlUp


i = Application.Match(emp, WSC.Range("B:B"), 0)
WSC.Rows(i).Delete Shift:=xlUp
MsgBox emp

Basically, this method is deleting the row. So if I have a table outline that has borders, and formatting, when it deletes the row, the table gets smaller every time. What I would like to do is clear the row data, and move everything below it up without actually removing the row.

The only method in my head I see working would be to insert a row above the match, and then remove it? Just wondering if there's an easier way.
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about moving the row to the bottom of the table and then deleting the values, like this

Code:
Sub testCutRow()
    Rows(r).Cut
    Rows(Range("A" & Rows.Count).End(xlUp).Offset(1).Row).Insert
    Rows(Range("A" & Rows.Count).End(xlUp).Row).ClearContents
End Sub

Add sheet references etc to match your requirements
 
Upvote 0
Think we're getting close with that.. That way is unfortunately killing my formatting though, and I can't seem to get it to delete (yet) from the bottom where it inserts the data

Code:
Sub Delete_employee()On Error Resume Next
Set myRange = Application.InputBox(Prompt:="Please click on the Employee you want to remove", _
Title:="Click on employee", Type:=8)
r1 = myRange.Row
c1 = myRange.Column
If myRange Is Nothing Then Exit Sub
emp = Cells(r1, c1).Value


x = InputBox("This action CANNOT be undone! Type YES to delete  - " & emp)
If UCase(x) <> "YES" Then
    MsgBox "Employee NOT deleted"
    Exit Sub
End If


Dim es As Worksheet, etd As Worksheet
Set es = Worksheets("Master Employee List")
Set etd = Worksheets("Jan Week 1")


r = Application.Match(emp, es.Range("A:A"), 0)
es.Rows(r).Delete Shift:=xlUp


i = Application.Match(emp, etd.Range("D:D"), 0)
[COLOR=#ff0000]etd.Rows(i).Cut
etd.Rows(Range("D" & Rows.Count).End(xlUp).Offset(55).Row).Insert
etd.Rows(Range("D" & Rows.Count).End(xlUp).Row).ClearContents[/COLOR]


'WORKING OLD
'etd.Rows(i).Delete Shift:=xlUp
MsgBox emp


Call Fill_it


End Sub

I got it going to the end of the table, but it's just inserting the data towards the bottom and filling up from the bottom going up.

I'm going to experiment..


Looks like the last line isn't working where the clear contents are.

Rows(Range("A" & Rows.Count).End(xlUp).Row).ClearContents
 
Last edited:
Upvote 0
Got it working with this..

Code:
i = Application.Match(emp, etd.Range("D:D"), 0)etd.Rows(i).Cut
etd.Rows(Range("D" & Rows.Count).End(xlUp).Offset(55).Row).Insert
etd.Rows(Range("D55").Row).ClearContents

So I'm cutting the row, then inserting that row at the bottom, then clearing it. Works for me! ha.. Now if I can fix this formatting issue so everything stays the same I'll be in business!!
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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