i'm looking for VB code that does the same as hitting F2 in excel

D

dn

when you record a macro hitting the F2 in a cell that contains 444, the
result is:
ActiveCell.FormulaR1C1 = "444"
i would like the code just to record the action of hitting the F2 not of
writing the existing cell formula
 
W

witek

dn said:
when you record a macro hitting the F2 in a cell that contains 444, the
result is:
ActiveCell.FormulaR1C1 = "444"
i would like the code just to record the action of hitting the F2 not of
writing the existing cell formula



Application.SendKeys "{F2}"
 
D

dn

Many thanks, can you pls let me know what's the key name for "Enter"
i have tried :
Application.SendKeys "{F2}"
Application.SendKeys "{Enter}"
and it doesn't work

rgds, david
 
D

Dave Peterson

I don't know what you're doing, but sending keystrokes is not usually a good way
to do things.

Maybe:

with activecell
.value = .value
'or
.formula = .formula
end with

There may be much better ways of doing what you need.
 
D

dn

Many thanks, this worked perfectly.
in a nut shell, i imported dates into excel in dd/mm/yy , for some reason
excel read it as if it was text and not a number, however, i found out that
if you just used F2 and Enter, it was able to read it as a number so i was
trying to do this through a macro. your proposal worked just fine.
many thanks
 
D

Dave Peterson

Be careful.

If I do this kind of thing with my USA settings (mdy order), I may end up with
dates--but they may not be the ones I want.

For instance:
01/02/03
would change to
January 2, 2003
for me.

If your windows regional settings have your short date in dmy format, you should
be ok. But you may want to make a note of a value and then do your conversion.
Then give that cell an unambiguous date format (mmmm dd, yyyy) to see if it's
what you expect.

I like to do this if my "dates" are in a single column
select the column
data|text to columns
fixed width (remove all lines)
and choose date dmy (to match the data)
and finish up.

If I need a macro, I'd record one when I did it manually.
 
D

dn

thanks, i didn't think of it but luckily for me the date and my windows are
in dmy format, rgds, david
 

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