VBScript to Sort a range by row

mipszzz

New Member
Joined
May 27, 2009
Messages
12
I have been searching Google and this forum but have not found a solution that works for me. Hopefully someone can help. I have very little scripting experience but I am really good at copying and pasting! ;)

I have a spreadsheet listing servers with a series of columns listing their features. I need to sort the features range for each row with a script. I can of course manually highlight the range of features for row 1, then sort it. Then move to row 2 and repeat. I want to be able to do this in a script. in addition, the number of servers in each spreadsheet can differ so I need to the script to be able to repeat the process until it runs out of servers listed in column 1

Any guidance would be greatly appreciated!

HostName
O/S
IP
Feature1
Feature2
Feature 3
Server1
Srv2008
10.0.40.10
DC
DNS
DHCP
Server2
Srv2003
10.0.40.11
File
Print
DFS
Server3
Srv2012
10.0.40.12
Exchange
IIS
Server4
Srv2012
10.0.44.10
Exchange
IIS
Server5
Srv2003
10.0.44.11
File
Print
DFS

<tbody>
</tbody>
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
maybe something like this? sheet name would need to be modifiedSub Macro1()
'
Application.ScreenUpdating = False
'Get Last Row

LastRow = Range("A1000000").End(xlUp).Row

'Sort
For i = 2 To LastRow
Range("D" & i & ":F" & i).Select
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("D" & i), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet2").Sort
.SetRange Range("D" & i & ":F" & i)
.Header = xlNo
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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