VBA Excel - Replace Enter key with Alt Enter

0 votes

I am trying to replace Enter key with Alt+Enter so that I can write multiline in cells with ease.

I have seen that there is a function Application.OnKey and Application.SendKeys and I wanted to use those something like this:

Application.OnKey "~" , Application.SendKeys("%~") 

But where do I place those? Or any other ideas?

Apr 6, 2022 in Database by Edureka
• 13,690 points
1,326 views

1 answer to this question.

0 votes

I created Button1 and assigned the Enter key to send Alt-Enter in its click mechanism, as you suggested in the question:

Sub Button1_onClick()

    Call Application.OnKey("~", "SendAltEnter")

End Sub

Sub SendAltEnter()

    Application.SendKeys ("%~")
    
End Sub

This does indeed re-route the Enter key, however it appears that Alt-Enter calls the procedure for the "Enter" part of "Alt-Enter" again, resulting in an infinite loop the first time you push enter after clicking the button, and you must restart your Excel application to clean it up.

I also tried it with another key near Enter, # (at least on German keyboards), which could be used instead of Alt-Enter:

Sub Button1_onClick()

    Call Application.OnKey("#", "SendAltEnter")

End Sub

Sub SendAltEnter()

    Application.SendKeys ("%~")
    
End Sub
answered Apr 11, 2022 by gaurav
• 23,260 points

Related Questions In Database

0 votes
1 answer
0 votes
1 answer

how do I calculate discount with if function in excel?

Suppose a customer gets a 10 percent ...READ MORE

answered Feb 23, 2022 in Database by gaurav
• 23,260 points
11,319 views
0 votes
1 answer

MS Excel - SumProduct formula with Loop

Drag this to the right of cell ...READ MORE

answered Mar 14, 2022 in Database by gaurav
• 23,260 points
637 views
0 votes
1 answer
0 votes
1 answer

Excel VBA - exit for loop

When we need to depart the For ...READ MORE

answered Mar 15, 2022 in Database by gaurav
• 23,260 points
844 views
0 votes
1 answer

Excel 2003 - Match Column A with Column B & Column C to correspond to Column B

Write a standard IF formula that compares ...READ MORE

answered Mar 15, 2022 in Database by gaurav
• 23,260 points
2,992 views
0 votes
1 answer

how do I calculate discount with if function in excel

Notes about the release; Frameworks to aim ...READ MORE

answered Mar 25, 2022 in Database by gaurav
• 23,260 points
737 views
0 votes
1 answer

Excel: Highlighting duplicates with exact matches

To enter the Advanced Filter dialogue box, ...READ MORE

answered Mar 24, 2022 in Database by gaurav
• 23,260 points
1,221 views
0 votes
1 answer

Is Excel Alt+Enter same as Newline character \n ?

According to the excel documentation, pressing alt+enter ...READ MORE

answered Mar 30, 2022 in Database by gaurav
• 23,260 points
4,741 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP