Share via

Excel VBA - Finish editing a Cell

Anonymous
2022-01-18T15:51:58+00:00

It's always the details that hang me up. :}

I have a macro that cuts and pastes rows to reorder them. It works unless the the User has started editing a cell and didn't hit return. Then the Cut does not succeed and then the macro fails on the Paste. Is there someway to force the completion of a manual cell edit at the beginning of the macro. Here's a snippet of my code.

For R\_Cnt1 = 7 To NumRows1

     If HDWSh.Range("A" & R\_Cnt1) = "O" Then

         If R\_Cnt1 <> L\_Cnt1 Then

             HDWSh.Rows(R\_Cnt1).Cut

             HDWSh.Rows(L\_Cnt1).Insert Shift:=xlShiftDown

         End If

         L\_Cnt1 = L\_Cnt1 + 1

     End If     

Next R_Cnt1

I tried adding a

Application.SendKeys "{Enter}", True

but that didn't do anything.

Thanks for your Help!

Microsoft 365 and Office | Excel | For business | MacOS

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2022-01-18T17:19:51+00:00

    You may be right that it's a BUG! I tried UNSELECT too and that didn't do anything either. Well... Onwards into the fog I go...:).

    Thanks for your help

    1 person found this answer helpful.
    0 comments No comments
  2. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2022-01-18T16:33:01+00:00

    Way! If you run it from the VBA debugger window it will run the macro while a cell is in mid edit.

    You think it does, but it doesn't. If it worked, your Sendkeys code would exit the Edit mode, right?

    It may be a detail that this window accepts input on a Mac in Edit mode ... this is a bug, it should be locked.

    However, in Edit mode the application is locked, whatever you try using a macro in Excel did not work.

    Andreas.

    0 comments No comments
  3. Anonymous
    2022-01-18T16:21:19+00:00

    Way! If you run it from the VBA debugger window it will run the macro while a cell is in mid edit. You are correct if you try to run it from the applications window, it won't start.

    Thanks for your reply!

    0 comments No comments
  4. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2022-01-18T16:08:18+00:00

    No way. If Excel is in Edit mode you can't run any macro at all.

    Andreas.

    0 comments No comments