Andrewryan3
Board Regular
- Joined
- Jun 13, 2017
- Messages
- 73
I have found this VBA which will sort all the sheets I have in a workbook, but I only want to sort a few....can someone tell me should I name all sheets in the () or how can I do this. There are sheets before and after the 42 that I need sorted....or is there a shorter easier way??
<code class="vb keyword">Sub</code> <code class="vb plain">SortAllSheets()</code>
<code class="vb spaces"> </code><code class="vb comments">'Updateby Extendoffice 20161216</code>
<code class="vb spaces"> </code><code class="vb keyword">Dim</code> <code class="vb plain">WS </code><code class="vb keyword">As</code> <code class="vb plain">Worksheet</code>
<code class="vb spaces"> </code><code class="vb plain">ActiveSheet.Range(</code><code class="vb string">"a1:f1"</code><code class="vb plain">).</code><code class="vb keyword">Select</code>
<code class="vb spaces"> </code><code class="vb plain">Selection.Copy</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 spaces"> </code><code class="vb plain">Application.ScreenUpdating = </code><code class="vb keyword">False</code>
<code class="vb spaces"> </code><code class="vb keyword">For</code> <code class="vb keyword">Each</code> <code class="vb plain">WS </code><code class="vb keyword">In</code> <code class="vb plain">Worksheets</code>
<code class="vb spaces"> </code><code class="vb plain">WS.Columns(</code><code class="vb string">"A:F"</code><code class="vb plain">).Sort Key1:=WS.Columns(</code><code class="vb string">"E"</code><code class="vb plain">), Order1:=xlDescending</code>
<code class="vb spaces"> </code><code class="vb keyword">Next</code> <code class="vb plain">WS</code>
<code class="vb spaces"> </code><code class="vb plain">ActiveSheet.Range(</code><code class="vb string">"A1"</code><code class="vb plain">).PasteSpecial Paste:=xlPasteAll</code>
<code class="vb spaces"> </code><code class="vb plain">Application.ScreenUpdating = </code><code class="vb keyword">True</code>
<code class="vb keyword">End</code> <code class="vb keyword">Sub</code>
<code class="vb keyword">Sub</code> <code class="vb plain">SortAllSheets()</code>
<code class="vb spaces"> </code><code class="vb comments">'Updateby Extendoffice 20161216</code>
<code class="vb spaces"> </code><code class="vb keyword">Dim</code> <code class="vb plain">WS </code><code class="vb keyword">As</code> <code class="vb plain">Worksheet</code>
<code class="vb spaces"> </code><code class="vb plain">ActiveSheet.Range(</code><code class="vb string">"a1:f1"</code><code class="vb plain">).</code><code class="vb keyword">Select</code>
<code class="vb spaces"> </code><code class="vb plain">Selection.Copy</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 spaces"> </code><code class="vb plain">Application.ScreenUpdating = </code><code class="vb keyword">False</code>
<code class="vb spaces"> </code><code class="vb keyword">For</code> <code class="vb keyword">Each</code> <code class="vb plain">WS </code><code class="vb keyword">In</code> <code class="vb plain">Worksheets</code>
<code class="vb spaces"> </code><code class="vb plain">WS.Columns(</code><code class="vb string">"A:F"</code><code class="vb plain">).Sort Key1:=WS.Columns(</code><code class="vb string">"E"</code><code class="vb plain">), Order1:=xlDescending</code>
<code class="vb spaces"> </code><code class="vb keyword">Next</code> <code class="vb plain">WS</code>
<code class="vb spaces"> </code><code class="vb plain">ActiveSheet.Range(</code><code class="vb string">"A1"</code><code class="vb plain">).PasteSpecial Paste:=xlPasteAll</code>
<code class="vb spaces"> </code><code class="vb plain">Application.ScreenUpdating = </code><code class="vb keyword">True</code>
<code class="vb keyword">End</code> <code class="vb keyword">Sub</code>
Last edited: