ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Press F2 with vba (https://www.excelbanter.com/excel-programming/410989-re-press-f2-vba.html)

Minitman

Press F2 with vba
 
Hey Joel,

Thanks for the reply.

I just tried SendKeys and could not get it to work consistently. Plus
the code was pasting contents of last cell - not what I need.

Here is what I tried (the first two cells only for this example):

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
Target.MergeArea.Activate
SendKeys "{F2}", True
If Target.MergeArea.Address = _
Range("pfCell_6").MergeArea.Address Then _
Range("pfCell_25").MergeArea.Select
If Target.MergeArea.Address = _
Range("pfCell_25").MergeArea.Address Then _
Range("pfCell_24").MergeArea.Select
....
End Sub

Any help to get this to work would be appreciated.

-Minitman


On Thu, 15 May 2008 03:08:01 -0700, Joel
wrote:

SendKeys Statement Example
This example uses the Shell function to run the Calculator application
included with Microsoft Windows. It uses the SendKeys statement to send
keystrokes to add some numbers, and then quit the Calculator. (To see the
example, paste it into a procedure, then run the procedure. Because
AppActivate changes the focus to the Calculator application, you can't single
step through the code.). On the Macintosh, use a Macintosh application that
accepts keyboard input instead of the Windows Calculator.

Dim ReturnValue, I
ReturnValue = Shell("CALC.EXE", 1) ' Run Calculator.
AppActivate ReturnValue ' Activate the Calculator.
For I = 1 To 100 ' Set up counting loop.
SendKeys I & "{+}", True ' Send keystrokes to Calculator
Next I ' to add each value of I.
SendKeys "=", True ' Get grand total.
SendKeys "%{F4}", True ' Send ALT+F4 to close Calculator.



"Minitman" wrote:

Greetings,

Is there anyway to press F2 inside of a macro with vba???

I can get my code to work if I manually press F2 after I hit enter.
But when I try to record it to see how vba interprets my keystrokes,
all it shows is this:

Range("AN5:AY5").Select
ActiveCell.FormulaR1C1 = "9/19/1981"
Range("BL5:BW5").Select
ActiveCell.FormulaR1C1 = ""

I hit Enter then F2. I did this twice in the sample above and this is
what gets recorded. In the first cell was a date and the second cell
was empty. I don't need to be copying or pasting over what is already
in the cell, I just need the ability to do so if needed.

Anyone have any ideas as to how to do this with vba?

Any help is always appreciated.

-Minitman




All times are GMT +1. The time now is 09:05 PM.

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