VBA Button to delete a row partially

4 Barrel Harold

New Member
Joined
Jun 15, 2018
Messages
21
Hey Guys and Gals, 4BBL Harold here with a problem that Ineed help with.<o:p></o:p>
On my sheet that I’m working on, I have a delete buttonsetup, here is brief description of the sheet<o:p></o:p>
I have two columns of information, 1ST columnsrange is E:M and 2ND Column O:W<o:p></o:p>
The rows start at row 12 and end at row 54<o:p></o:p>
Now here is what I’m trying to accomplish, if I select “H34”at random and press my VBA delete button, I need it to delete E:M on row 34without effecting O:W on same row and if I were to select another random cellon another row like R50 and press the same button it would delete O:W on row 50 and move lowerrows up O:W without deleting anything in E:M same row<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
Application.ScreenUpdating = False<o:p></o:p>
ActiveSheet.Unprotect<o:p></o:p>
Dim ldel As Long<o:p></o:p>
ldel = MsgBox("Are You Sure You Want To DELETE SELECTEDITEM?", vbQuestion + vbYesNo)<o:p></o:p>
If ldel <> vbYes Then Exit Sub<o:p></o:p>
ActiveCell.EntireRow.Delete Shift:=xlShiftDown ßThis is the row I need Help on<o:p></o:p>
ActiveSheet.Protect<o:p></o:p>
Application.ScreenUpdating = True<o:p></o:p>
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Welcome to the Board!

Are you wanting to actually delete those cells, so everything underneath it moves up, or do you simply want to clear the contents of those cells, but not move any other data on the sheet around?
 
Upvote 0
Hi & welcome to the board.
How about
Code:
Application.ScreenUpdating = False
ActiveSheet.Unprotect
If MsgBox("Are You Sure You Want To DELETE SELECTEDITEM?", vbQuestion + vbYesNo) = vbYes Then
   Select Case ActiveCell.Column
      Case 5 To 13
         Range("E" & ActiveCell.row).Resize(, 9).Delete xlShiftUp
      Case 15 To 23
         Range("O" & ActiveCell.row).Resize(, 9).Delete xlShiftUp
   End Select
End If
ActiveSheet.Protect
Application.ScreenUpdating = True
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
Can the case code also be used for adding a row?? If so how would this part of the code be rewritten

Case 15 To 23
Range("O" & ActiveCell.row).Resize(, 9).Delete xlShiftUp
 
Upvote 0
Replace
Code:
.Delete xlShiftUp
with .Insert
 
Upvote 0

Forum statistics

Threads
1,214,414
Messages
6,119,373
Members
448,888
Latest member
Arle8907

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