<code class="vb keyword">Sub</code> <code class="vb plain">CombineMultipleWorksheets()</code>
<code class="vb spaces"> </code><code class="vb keyword">Dim</code> <code class="vb plain">i </code><code class="vb keyword">As</code> <code class="vb keyword">Integer</code>
<code class="vb spaces"> </code><code class="vb keyword">Dim</code> <code class="vb plain">xTCount </code><code class="vb keyword">As</code> <code class="vb keyword">Variant</code>
<code class="vb spaces"> </code><code class="vb keyword">Dim</code> <code class="vb plain">xWs </code><code class="vb keyword">As</code> <code class="vb plain">Worksheet</code>
<code class="vb spaces"> </code><code class="vb keyword">On</code> <code class="vb keyword">Error</code> <code class="vb keyword">Resume</code> <code class="vb keyword">Next</code>
<code class="vb plain">LInput:</code>
<code class="vb spaces"> </code><code class="vb plain">xTCount = Application.InputBox(</code><code class="vb string">"The number of title rows"</code><code class="vb plain">, </code><code class="vb string">""</code><code class="vb plain">, </code><code class="vb string">"1"</code><code class="vb plain">)</code>
<code class="vb spaces"> </code><code class="vb keyword">If</code> <code class="vb plain">TypeName(xTCount) = </code><code class="vb string">"Boolean"</code> <code class="vb keyword">Then</code> <code class="vb keyword">Exit</code> <code class="vb keyword">Sub</code>
<code class="vb spaces"> </code><code class="vb keyword">If</code> <code class="vb keyword">Not</code> <code class="vb plain">IsNumeric(xTCount) </code><code class="vb keyword">Then</code>
<code class="vb spaces"> </code><code class="vb plain">MsgBox </code><code class="vb string">"Only can enter number"</code><code class="vb plain">, , </code><code class="vb string">"Kutools for Excel"</code>
<code class="vb spaces"> </code><code class="vb keyword">GoTo</code> <code class="vb plain">LInput</code>
<code class="vb spaces"> </code><code class="vb keyword">End</code> <code class="vb keyword">If</code>
<code class="vb spaces"> </code><code class="vb keyword">Set</code> <code class="vb plain">xWs = ActiveWorkbook.Worksheets.Add(Sheets(1))</code>
<code class="vb spaces"> </code><code class="vb plain">xWs.Name = </code><code class="vb string">"Combined"</code>
<code class="vb spaces"> </code><code class="vb plain">Worksheets(2).Range(</code><code class="vb string">"A1"</code><code class="vb plain">).EntireRow.Copy Destination:=xWs.Range(</code><code class="vb string">"A1"</code><code class="vb plain">)</code>
<code class="vb spaces"> </code><code class="vb keyword">For</code> <code class="vb plain">i = 2 </code><code class="vb keyword">To</code> <code class="vb plain">Worksheets.Count</code>
<code class="vb spaces"> </code><code class="vb plain">Worksheets(i).Range(</code><code class="vb string">"A1"</code><code class="vb plain">).CurrentRegion.Offset(</code><code class="vb keyword">CInt</code><code class="vb plain">(xTCount), 0).Copy _</code>
<code class="vb spaces"> </code><code class="vb plain">Destination:=xWs.Cells(xWs.UsedRange.Cells(xWs.UsedRange.Count).Row + 1, 1)</code>
<code class="vb spaces"> </code><code class="vb keyword">Next</code>
<code class="vb keyword">End</code> <code class="vb keyword">Sub</code>