Microsoft KB Archive/37506

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.



Editing a Worksheet Formula from a Macro in Excel

Last reviewed: November 4, 1994
Article ID: Q37506



2.x 3.00 4.00 4.00a 5.00 | 2.20 2.21 3.00

WINDOWS                  | OS/2

kbusage The information in this article applies to:

  • Microsoft Excel for Windows, version 2.x, 3.0, 4.0, 4.0a, 5.0
  • Microsoft Excel for OS/2 versions 2.2, 2.21, 3.0

SUMMARY

When you edit a formula contained in a worksheet from a macro, using the SEND.KEYS function replicates the manual editing steps, as the following example illustrates:

   =ACTIVATE("sheet1.xls")
   =SELECT("r12c2")
   =SEND.KEYS("{F2}editingtext~")

In the SEND.KEYS line, {F2} takes you into edit mode on the formula bar. "editingtext" is the string of keystrokes to press if you are manually editing the formula. The tilde (~ or {ENTER}) terminates the edit mode and enters the formula into the selected cell. Note: The SEND.KEYS text is not sent until a dialog box is displayed, or the macro is finished, so the above cannot be repeated in a macro.

MORE INFORMATION

Examples of SEND.KEYS function editing are as follows:

  1. Original Formula: =SUM(A1:A10)

       Editing Command:   =SEND.KEYS("{F2}*B2~")
       Resulting Formula: =SUM(A1:A10)*B2.
    
  2. Original Formula: =SUM(A1:A10)

       Editing Command:   =SEND.KEYS("{F2}{LEFT}{BS}{BS}{BS}C8~")
       Resulting Formula: =SUM(A1:C8)
    

In the second example, {LEFT} moves the insertion point to the left one character, and {BS} backspaces one character each time, deleting "A10".

REFERENCES

For more information on using the SEND.KEYS function, query on:

   send.keys and on.time



KBCategory: kbusage

KBSubcategory:

Additional words: 5.00 2.00 2.0 2.01 2.1 2.10 2.2 2.21 2.20 3.00
3.0 4.00 4.0


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 4, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.