Select next row at column A after row has been deleted

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I use the code below to allow the user to select a customer in column A which they wish to delete.
It works fine but has an issue once the row has been deleted.

This is the user is unable to use the navigation arrows to move from the selected cell.
The user has to select a cell then a mouse click before they can use the navigation arrow.

Example.
User selects a customer at A111
The code is run & that row is now deleted.
The user now sees the msgbox which confirms that customers row was deleted.
At this point the selected cell is A111 BUT using the navigation arrows does nothing.

So can you advise please once the user at A111 is deleted After the user cilcks OK to the confirmation message box the next cell is then selected Thus A112 in this case.
For future row deletions example A99 once deleted user clicks OK to confiremation message & the cell A100 is selected

Rich (BB code):
Private Sub CommandButton3_Click()
   
    Dim answer As Integer

    If ActiveCell.Column = 1 Then
        answer = MsgBox("DELETE CUSTOMERS ROW " & ActiveCell.Value, vbYesNo + vbCritical)
        If answer = vbYes Then
            ActiveCell.EntireRow.Delete
            MsgBox "CUSTOMERS ROW NOW DELETED", vbInformation
        End If
    Else
        MsgBox "YOU NEED TO SELECT A CUSTOMER IN COLUMN A", vbCritical, "SELECT CUSTOMER MESSAGE"
    End If

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
@ipbr21054 Is your issue that you are test running this code from within the vba editor?

If so then you will need the click on the sheet to to get the focus back on the sheet rather than the editor.
If run from a button in the sheet it works fine for me.
 
Upvote 0
Hi,
Im using it on the sheet.
It deletes the customers row & then selects the same row reference example A111 it now now i am unable to move from that cell unless i use the mouse.

So currently if the case is it selects the same cell once the user clicks OK on the msgbox how would i add a line of code so something like,
Active cell + 1 so it the moves its focus from A111 to A112
 
Upvote 0
Ok. After deletion of the selected row the data row below effectively moves up anyway but if you still want to select a row down then try this.

Private Sub CommandButton3_Click()
Dim answer As Integer
Dim r As Long
If ActiveCell.Column = 1 Then
r = ActiveCell.Row '**************
answer = MsgBox("DELETE CUSTOMERS ROW " & ActiveCell.Value, vbYesNo + vbCritical)
If answer = vbYes Then
ActiveCell.EntireRow.Delete
MsgBox "CUSTOMERS ROW NOW DELETED", vbInformation
End If
Else
MsgBox "YOU NEED TO SELECT A CUSTOMER IN COLUMN A", vbCritical, "SELECT CUSTOMER MESSAGE"
End If
Cells(r + 1, 1).Select '*************
End Sub

For me, after the running of the above, the arrow keys function normally without any need to hit enter key first.
Hope that helps.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,195
Messages
6,123,572
Members
449,108
Latest member
rache47

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