ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Creating what should be a simple macro (https://www.excelbanter.com/excel-discussion-misc-queries/138847-creating-what-should-simple-macro.html)

Dwight

Creating what should be a simple macro
 
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.



Gary''s Student

Creating what should be a simple macro
 
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.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

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.



Dwight

Creating what should be a simple macro
 
Thanks, that's exactly what I needed.

"Gary''s Student" wrote:

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.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

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.



Gary''s Student

Creating what should be a simple macro
 
You are very welcome. If you ever have trouble using SendKeys to change a
cell, include the DoEvents prior to going to another cell.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

Thanks, that's exactly what I needed.

"Gary''s Student" wrote:

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.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

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.



Dwight

Creating what should be a simple macro
 
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?

"Gary''s Student" wrote:

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.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

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.



Gary''s Student

Creating what should be a simple macro
 
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.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

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?

"Gary''s Student" wrote:

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.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

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.



Dwight

Creating what should be a simple macro
 
Thanks, that makes sense, and I'll see what I can do.



"Gary''s Student" wrote:

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.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

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?

"Gary''s Student" wrote:

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.
--
Gary''s Student - gsnu200715


"Dwight" wrote:

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.




All times are GMT +1. The time now is 06:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com