View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Lakehills Lakehills is offline
external usenet poster
 
Posts: 7
Default Problem sorting a range of columns using VBA

Thanks all but after recording a macro again and tweaking it slightly,
came up with the below code which seems to work perfectly.

Workbooks(glbMasterFileName).Worksheets("System Data").Activate
LastUsedEmplRow = (Worksheets("System
Data").Range("F65536").End(-4162).Row) - 0 'Returns last used row

Range("F2:H" & LastUsedEmplRow).Select
ActiveWorkbook.Worksheets("System Data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("System Data").Sort.SortFields.Add
Key:=Range("F2") _
, SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("System Data").Sort
.SetRange Range("F3:H" & LastUsedEmplRow)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Thanks,
Lakehills