VBA to sort range of rows based on value

shaun86

New Member
Joined
Oct 20, 2017
Messages
16
Hi I am completely new to the coding side of Excel (using Excel 2013) and am creating a spreadsheet for where I work. Basically its a development chart that tracks the readiness of individual employees filled out by our team leaders and there will be a master one that links all the info presented that the senior management can look at and assess quickly rather than gathering each individual workbook. Here is the basic layout:

157cga0.jpg


I have made a conditional format that changes the cell's to green, yellow, and red (simply fills it in and changes font color). But I would like for the rows to automatically arrange themselves in ascending order based on the combined value of the Status and Readiness cells, so 2 would be the lowest value and 6 would be the highest. I don't know how to control the range of rows that sorts itself. I have done a little bit of research and fiddled with this code:

<code class="vb keyword">Private</code> <code class="vb keyword">Sub</code> <code class="vb plain">Worksheet_Change(</code><code class="vb keyword">ByVal</code> <code class="vb plain">Target </code><code class="vb keyword">As</code> <code class="vb plain">Range)</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 keyword">If</code> <code class="vb keyword">Not</code> <code class="vb plain">Intersect(Target, Range(</code><code class="vb string">"B:B"</code><code class="vb plain">)) </code><code class="vb keyword">Is</code> <code class="vb keyword">Nothing</code> <code class="vb keyword">Then</code>
<code class="vb plain">Range(</code><code class="vb string">"B1"</code><code class="vb plain">).Sort Key1:=Range(</code><code class="vb string">"B2"</code><code class="vb plain">), _</code>
<code class="vb plain">Order1:=xlAscending, Header:=xlYes, _</code>
<code class="vb plain">OrderCustom:=1, MatchCase:=</code><code class="vb keyword">False</code><code class="vb plain">, _</code>
<code class="vb plain">Orientation:=xlTopToBottom</code>
<code class="vb keyword">End</code> <code class="vb keyword">If</code>
<code class="vb keyword">End</code> <code class="vb keyword">Sub

I found it on a search of someone doing something similar but what I want to accomplish is a little different and I know very little about coding. Any insight on this would be incredibly helpful and if I was unclear in any way please let me know. Thanks in advance!</code>
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
The code I'm using above works on column B (starting at B5 specifically I believe), and arranges the cells in column A also, but I don't fully understand how the code works. If I wanted the code to take the value from column D (starting at D5 and to arrange columns A:F based on the value in column D what would I have to change? Is it possible to put multiple vba codes in there to work on different ranges of rows?
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top