VBA code not working correctly

Takes2ToTango

Board Regular
Joined
May 23, 2023
Messages
69
Office Version
  1. 365
Platform
  1. Windows
Hi All, Running into a problem. The below code doesn't properly run. Once it gets to 'Worksheets("Revision").Range("G16") = ActiveCell it seems to run over itself. Sometimes the range won't be inputted with active cell and 9 out of 10 times the row will not be deleted and will remain. Any help would be appreciated.

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

If Not Intersect(Target, Range("A:A")) Is Nothing Then Cancel = True

If MsgBox("Do you want to remove the flag for this part?", vbYesNo) = vbYes Then

            Cells(ActiveCell.Row, 1).Interior.ColorIndex = 0
            Cells(ActiveCell.Row, 2).Interior.ColorIndex = 0
            Cells(ActiveCell.Row, 3).Interior.ColorIndex = 0
            Cells(ActiveCell.Row, 6).Interior.ColorIndex = 0
            Cells(ActiveCell.Row, 7).Interior.ColorIndex = 0
            Cells(ActiveCell.Row, 8).Interior.ColorIndex = 0
            Cells(ActiveCell.Row, 9).Interior.ColorIndex = 0

Worksheets("Revision").Range("G16") = ActiveCell

Application.Wait (Now + TimeValue("00:00:02"))

call DeleteRow

End Sub


Sub DeleteRow

Dim k As Integer

If Worksheets("Revision").Range("G16") = "" Then
Exit Sub

Else

For k = 30 To 1 Step -1
If Cells(k, 3).Value = Worksheets("Revision").Range("G16") Then
Cells(k, 3).EntireRow.Delete
End If
Next k

End If

End If

End Sub
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
If this Private Sub is from Worksheets("Revision") then you don't need to define it in the code, you can just use Range. Also, I don't see where you actually use the ActiveCell to do anything. I don't think it's needed.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,249
Members
452,623
Latest member
Techenthusiast

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