Use VBA to open an Excel cell for Edit

M

Michael Gree

Hi,
How do I open a cell for edit from code ie as if the user
had pressed F2...
Regards
Michael Green
 
M

Michael Green

Tom,
Many thanks for that - it worked.

However I'm concerned that SendKeys only works on the
Active window. Do you know a way to ensure the key
strokes go to the correct window ?

Regards
Michael
 
T

Tom Ogilvy

You can only edit in the active window, so that shouldn't be an issue.

I am not sure why you want to do this, but if you want to change the value
in a cell, you certainly don't need to put excel into edit mode (where code
doesn't run anyway).
 
M

Michael Green

Tom,
Thanks for that.

The reason I want the cell open for editing is as a nicety
for the user. Before this last line of code there is code
to insert a new row, specially format it with validation
etc. I then position the active cell so the user can
start entering data.

Regards
Michael Green
 
J

John Wilson

Michael,

Getting back to what Tom said..why would you want to do this?
As long as you're in VBA, create a UserForm and let the user
enter data into a textbox. You can validate the data in the textbox
a lot easier than in a cell and when (via coding) you're certain
it's correct, write it to the cell in whatever format you want.

John
 

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