Macro to move two cells up deleting the two above cell

bumperjoe

New Member
Joined
Feb 4, 2006
Messages
33
hello,
I need to move a cell (A2) and it's adjacent cell(B2) up and delete the two cells above it (A1) and (B1)



Thanks
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Re: how to use a macro to move two cells up deleting the two above cell

Select A1:B1, Delete/Shift Cells UP
 
Upvote 0
Re: how to use a macro to move two cells up deleting the two above cell

Range("A1:B1").Delete xlShiftUp
 
Upvote 0
Re: how to use a macro to move two cells up deleting the two above cell

Your wanting to do this one at a time?

So if you click on A20 you want to delete A19 and B19 and shift up.
Is that what you want.

Why not explain what criteria you use for deciding what cells to delete and we could write script to do all one thousand at one click of a button.
 
Upvote 0
Re: how to use a macro to move two cells up deleting the two above cell

If you really want to do this one at a time use this script.
Double click on cell in column ("A") of the row you want to delete.
Script will delete and shiftup columns A and B

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 1 Then
Cancel = True
Dim ans As Long
ans = Target.Row
Range(Cells(ans, 1), Cells(ans, 2)).Delete xlShiftUp
End If
End Sub
 
Last edited:
Upvote 0
Re: how to use a macro to move two cells up deleting the two above cell

Code:
Sub Dlt ()
If Selection.Cells.Count>1 Then Exit Sub
Selection(0).resize(,2).Delete xlShiftUp
End Sub
 
Upvote 0
Re: how to use a macro to move two cells up deleting the two above cell

If you really want to do this one at a time use this script.
Double click on cell in column ("A") of the row you want to delete.
Script will delete and shiftup columns A and B

This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 1 Then
Cancel = True
Dim ans As Long
ans = Target.Row
Range(Cells(ans, 1), Cells(ans, 2)).Delete xlShiftUp
End If
End Sub

thank you. it work so great!! sorry I was not clearer in the original post. I forget people cannot read minds
One more question. What do you change to make it start in say column D or E
 
Upvote 0
Re: how to use a macro to move two cells up deleting the two above cell

Well if you want this to apply to columns 1 4 and 6 then use this

Look at top line of code and you will see:
Target.column = 1 or 4 or 5

Change these if needed.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 1-31-18 1:35 PM EST
If Target.Column = 1 Or Target.Column = 4 Or Target.Column = 5 Then
Cancel = True
ActiveCell.Resize(, 2).Delete xlShiftUp
End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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