VBA equivalent to "Return/Enter" Key

J

JMay

I've got code that is working up to a point **and stops** -- the screen
(bottom left shows I'm in Edit Mode) - and the cursor is "inside" a cell --
all that I have to do is manually press enter and it completes. soooooo
obviously I'd like to incorporate this "last-step" in the code. Can someone
tell me what I should add to the code to have it complete the update.
TIA,
 
J

Joe 90

Use

Sendkeys {ENTER}
or
Sendkeys ~

See vb help using keyword sendkeys

Cheers

Joe
 
R

Robin Hammond

If I understand you correctly, you are editing a cell but want VBA to then
hit enter. I don't think it can be done. Once you go into edit mode, Excel
has full control, and VBA will not resume operation until editing is
complete.

Is there a particular need to do whatever you are trying to do in this
fashion, or could you look at an alternative technique?

Robin Hammond
www.enhanceddatasystems.com
Check out our XspandXL add-in
 
J

JMay

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If ActiveCell.Font.Strikethrough = True Then
ActiveCell.Font.Strikethrough = False
Else
ActiveCell.Font.Strikethrough = True
End If
SendKeys {Enter} <<< This won't take ???
End Sub

Can you help?
TIA
 
J

John Wilson

Joe,

Try:
Application.SendKeys "{Enter}"
Worked for me. Win XP, XL2000

John
 
T

Thomas

SendKeys "{Enter}",true
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If ActiveCell.Font.Strikethrough = True Then
ActiveCell.Font.Strikethrough = False
Else
ActiveCell.Font.Strikethrough = True
End If
SendKeys {Enter} <<< This won't take ???
End Sub

Can you help?
TIA
 
T

Tim Zych

The way I read it is that when you double-click the cell, the event is
triggered so the macro is run, and then Excel puts you in edit mode. Cancel
= True takes care of the edit mode problem.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target _
As Range, Cancel As Boolean)
With Target(1, 1)
.Font.Strikethrough = Not .Font.Strikethrough
End With
Cancel = True
End Sub
 
J

JMay

Thanks to all; I also ended up adding to a UDF SumNonStrukeThruAmts() the
line:

Application.volatile

Which makes my full procedure work great
Tks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top