Microsoft KB Archive/110709: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 53: Line 53:
To work around this problem, you may need to modify the recorded code. The modified code should resemble the following:
To work around this problem, you may need to modify the recorded code. The modified code should resemble the following:
<pre class="codesample">  Sub Macro1()
<pre class="codesample">  Sub Macro1()
       Range(&quot;A1&quot;).Select
       Range("A1").Select
       Selection.Cut (Range(&quot;B1&quot;))
       Selection.Cut (Range("B1"))
       Range(&quot;B1&quot;).Select
       Range("B1").Select
   End Sub
   End Sub
                 </pre>
                 </pre>
Line 74: Line 74:
<li>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.</li>
<li>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.</li>
<li>Select the contents of cell A1 and drag it to cell B1.</li>
<li>Select the contents of cell A1 and drag it to cell B1.</li>
<li>When you are prompted with the &quot;Replace contents of destination cells?&quot; message, choose OK.</li>
<li>When you are prompted with the "Replace contents of destination cells?" message, choose OK.</li>
<li>To stop the Macro Recorder, choose Record Macro from the Tools menu, and then choose Stop Recording.</li>
<li>To stop the Macro Recorder, choose Record Macro from the Tools menu, and then choose Stop Recording.</li>
<li>Switch to the new Visual Basic module.</li></ol>
<li>Switch to the new Visual Basic module.</li></ol>
Line 80: Line 80:
The following subroutine should be contained in the module:
The following subroutine should be contained in the module:
<pre class="codesample">  Sub Macro1()
<pre class="codesample">  Sub Macro1()
       Range(&quot;A1&quot;).Select
       Range("A1").Select
   ExecuteExcel4Macro &quot;CUT(Range(&quot;A1&quot;),Range(&quot;B1&quot;))&quot;
   ExecuteExcel4Macro "CUT(Range("A1"),Range("B1"))"
       Range(&quot;B1&quot;).Select
       Range("B1").Select
   End Sub
   End Sub
                 </pre>
                 </pre>
Line 93: Line 93:
# From the list of macros, select Macro1 and choose the Run button.
# From the list of macros, select Macro1 and choose the Run button.


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


</div>
</div>

Latest revision as of 11:19, 20 July 2020

Article ID: 110709

Article Last Modified on 10/10/2006



APPLIES TO

  • Microsoft Excel 5.0 Standard Edition



This article was previously published under Q110709

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: XL5

Keywords: kbprogramming KB110709