XL5: Drag to Replace in Recorded Macro Returns Invalid Code

ID: Q110709


The information in this article applies to:
  • Microsoft Excel for Windows, version 5.0


SUMMARY

In Microsoft Excel version 5.0 for Windows, when you are recording a Visual Basic subroutine and you drag a cell or range of cells to another cell or range of cells to replace the original information, the recorded subroutine may contain syntax errors that prevent it from functioning correctly.


WORKAROUND

To work around this problem, you may need to modify the recorded code. The modified code should resemble the following:


   Sub Macro1()
      Range("A1").Select
      Selection.Cut (Range("B1"))
      Range("B1").Select
   End Sub 
The third line, which originally contained invalid code, has been replaced by a line of code that performs the correct action.


MORE INFORMATION

Steps to Reproduce Problem

  1. In a new workbook, create a new worksheet and enter the following values:
    
            A1: Alpha   B1: Bravo 


  2. From the Tools menu, choose Record Macro, and then choose Record New Macro.


  3. In the Record New Macro dialog box, choose the Options button. In the Expanded Record New Macro dialog box, Under Language, verify that the Visual Basic option is selected. Choose OK to begin recording.


  4. Select the contents of cell A1 and drag it to cell B1.


  5. When you are prompted with the "Replace contents of destination cells?" message, choose OK.


  6. To stop the Macro Recorder, choose Record Macro from the Tools menu, and then choose Stop Recording.


  7. Switch to the new Visual Basic module.


The following subroutine should be contained in the module:

   Sub Macro1()
      Range("A1").Select
   ExecuteExcel4Macro "CUT(Range("A1"),Range("B1"))"
      Range("B1").Select
   End Sub 
The third line (which starts with the ExecuteExcel4Macro method) will appear in red, indicating that the line contains a syntax error.

  1. Switch to the worksheet.


  2. In cell A1, type Charlie.


  3. With cell A1 selected, choose Macro from the Tools menu.


  4. From the list of macros, select Macro1 and choose the Run button.


You will receive the error message "Syntax error" and the third line of the subroutine will be selected.

Additional query words:

Keywords : kbprg
Version : WINDOWS:5.0
Platform : WINDOWS
Issue type :


Last Reviewed: October 18, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.