Creating what should be a simple macro

G

Guest

I want to create a macro that will start in the current cell, give a carriage
return to go to the cell below, give a F2 keystroke, then a Home keystroke
and end.

I know this is very basic, but I can't seem to get it to work.

Any assistance will be greatly appreciated.
 
G

Guest

Sub dwight()
Application.SendKeys "{ENTER}"
DoEvents
Application.SendKeys "{F2}"
Application.SendKeys "{ENTER}"
DoEvents
Application.SendKeys "{HOME}"
End Sub

You may need to back up a row.
 
G

Guest

Thanks, that's exactly what I needed.

Gary''s Student said:
Sub dwight()
Application.SendKeys "{ENTER}"
DoEvents
Application.SendKeys "{F2}"
Application.SendKeys "{ENTER}"
DoEvents
Application.SendKeys "{HOME}"
End Sub

You may need to back up a row.
 
G

Guest

You are very welcome. If you ever have trouble using SendKeys to change a
cell, include the DoEvents prior to going to another cell.
 
G

Guest

I put that in and had one too many returns, so I took one out.

After it does the line down, the F2 and the Home, I need to enter one
character at the front of the cell then turn it off.

It works great until I want it to turn off then it deletes what I typed and
sits at the front of that cell blinking.

I need it to either stop after my character I imput or take the first
character from the cell to it's left and add it on the front for me in a loop.

Now what?
 
G

Guest

Let's start with the HOME. Say we want to enter the character Z in that
first column

Sub dwight()
Application.SendKeys "{ENTER}"
DoEvents
Application.SendKeys "{F2}"
Application.SendKeys "{ENTER}"
DoEvents
Application.SendKeys "{HOME}"
DoEvents
Application.SendKeys "{F2}"
Application.SendKeys "Z"
Application.SendKeys "{ENTER}"
DoEvents
End Sub

Here's what's happening:
1. the HOME gets us back to column A
2. the DoEvents make sure Excel is ready to receive data
3. the F2 put the cell in edit mode
4. the "Z" dumps Z into the cell
5. the ENTER completes the entry
6. the final DoEvents makes sure that Excel has processed steps 3,4,5

That's why the DoEvents is so important:

Sendkeys is like pitching softballs. DoEvents allows the catcher to catch
the balls.
 

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