Limit Delete row and move xlUp to 1 column.

JulianvO

New Member
Joined
Sep 9, 2022
Messages
29
Office Version
  1. 2021
Platform
  1. Windows
Greetings

I have a Table - "ItemDB" - that has 3 columns namely Item, Qty and Taken.
Table starts at B5 through to F5 - Headings

My Code:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

If Not Intersect(Target, Range("B:F")) Is Nothing Then

Cancel = True

With Target

.EntireRow.Range("B1:F1").ClearContents
.Value = ""
.Offset(1, 0).Select
.Select

End With

End If

If Not Target Is Nothing Then Target.Delete xlUp

Problem:

When I DoubleClick in any column within the table, the row is deleted.

I need the DoubleClick delete row to only be available in Column B.

Can someone assist me?

Thanks

End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
This is telling the code to run when any cell in columns B:F is Double clicked, try changing the B:F

Greetings Mark

Thanks for the reply. Implemented the change, but Double-clicking in either columns C or D, still deletes an entry in column B.
 
Upvote 0
Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Not Intersect(Target, Range("B:B")) Is Nothing Then

        Cancel = True

        With Target

            .EntireRow.Range("B1:F1").ClearContents
        End With
    End If
    If Not Intersect(Target, Range("B:B")) Is Nothing Then Target.Delete xlUp
End Sub

although the below probably does the same

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Not Intersect(Target, Range("B:B")) Is Nothing Then

        Cancel = True

        With Target

            .EntireRow.Range("B1:F1").ClearContents
            .Delete xlUp
        End With
    End If

End Sub
 
Upvote 0
Solution
Rich (BB code):
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Not Intersect(Target, Range("B:B")) Is Nothing Then

        Cancel = True

        With Target

            .EntireRow.Range("B1:F1").ClearContents
        End With
    End If
    If Not Intersect(Target, Range("B:B")) Is Nothing Then Target.Delete xlUp
End Sub

although the below probably does the same

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Not Intersect(Target, Range("B:B")) Is Nothing Then

        Cancel = True

        With Target

            .EntireRow.Range("B1:F1").ClearContents
            .Delete xlUp
        End With
    End If

End Sub
Greetings Mark

Tried both the above solutions. They both work as required.

Will use the second solution, as it is cleaner in appearance.

Thanks again for your kind assistance. Much appreciated.
 
Upvote 0
Greetings Mark

Tried both the above solutions. They both work as required.

Will use the second solution, as it is cleaner in appearance.

Thanks again for your kind assistance. Much appreciated.
Note: When marking a post as the solution, please mark the original post actually containing the solution, and not your own reply back acknowledging that some other post is the solution.
I have gone ahead and updated it on this thread for you.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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