Macro for clearing contents in a rage and cut past the available data from below

thespardian

Board Regular
Joined
Aug 31, 2012
Messages
119
Office Version
  1. 2016
  2. 2013
Platform
  1. Windows
Hi there!
I want a macro which can perform following
If any cell from a range (M10 : P999) is selected, clear the contents of the active cell row (e.g M17 or N17 or O17 or P17 is selected, clear the data from M17:P17),
Then look below the empty row and cut the available data from range (M18:P999)
And paste all the cut data in M17 .
I just want to delete the row without disturbing the row as i have data in the same row in other columns (col L and Col Q are empty)
Any help will be highly appreciated.

Here is the link for excel workbook. Workbook

Q2.png
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
How about
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Not Intersect(Target, Range("M10:P999")) Is Nothing Then
      Intersect(Target.EntireRow, Range("M:P")).Delete xlUp
      Cancel = True
   End If
End Sub
 
Upvote 0
I want to assign this macro to a button. How can i do it. Pardon me for my ignorance about vb codes therefore i couldn't explain it in my question . The above code is working very well . Just one issue i.e it work spontaneously. I just want to run this code though a button i already created.

Thanks a lot for your guidance.
 
Upvote 0
I want to assign this macro to a button. How can i do it. Pardon me for my ignorance about vb codes therefore i couldn't explain it in my question . The above code is working very well . Just one issue i.e it work spontaneously. I just want to run this code though a button i already created.

Thanks a lot for your guidance.
Will you be selecting a single cell?
Yes Single cell
 
Upvote 0
How about
VBA Code:
Sub thespardian()
   Dim Rng As Range
   If Not Intersect(ActiveCell, Range("M10:P999")) Is Nothing Then
      Intersect(ActiveCell.EntireRow, Range("M:P")).Delete xlUp
   End If
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub thespardian()
   Dim Rng As Range
   If Not Intersect(ActiveCell, Range("M10:P999")) Is Nothing Then
      Intersect(ActiveCell.EntireRow, Range("M:P")).Delete xlUp
   End If
End Sub
You have been always a blessing for me on this forum. You always gave me the strength of knowledge for which i am really thankful to you from the bottom of my heart.
 
Upvote 0

Forum statistics

Threads
1,214,621
Messages
6,120,563
Members
448,972
Latest member
Shantanu2024

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