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 in Database by Edureka
• 13,640 points
49 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 by gaurav
• 13,460 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 in Database by gaurav
• 13,460 points
580 views
0 votes
1 answer

MS Excel - SumProduct formula with Loop

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

answered Mar 14 in Database by gaurav
• 13,460 points
27 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 in Database by gaurav
• 13,460 points
38 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 in Database by gaurav
• 13,460 points
83 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 in Database by gaurav
• 13,460 points
43 views
0 votes
1 answer

Excel: Highlighting duplicates with exact matches

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

answered Mar 24 in Database by gaurav
• 13,460 points
29 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 in Database by gaurav
• 13,460 points
72 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP