Вы находитесь на странице: 1из 3

I have a macro that i want to add in it so that is will do a custom sort.

I would like it to look


ad column M and look at the color and sort it. The row count will change but it will always
start at row 2. After it is sorted by color from column M it needs to sort by number in
column A. So it would end up with RGB(148, 138, 84) grouped on top, RGB(219, 155, 153)
in the middle and RGB(179, 129, 217) on the bottom but in each color grouping sorted by
number from column A. Any ideas? Thanks!

Sub SortByColour()
Dim wks As Worksheet

' only tab downtime is active sheet for this VBA


Set wks = Downtime

With wks.Sort
With .SortFields
.Clear
.Add(wks.Range("E7:E5000"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 199, 206)
.Add(wks.Range("E7:E5000"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 217, 102)
.Add(wks.Range("E7:E5000"), xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(198, 239, 206)
.Add Key:=wks.Range("M7:M5000"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
End With
.SetRange wks.Range("E6").CurrentRegion
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

Sub DFile()

Dim Dir_Path, iMaxAge, oFSO, oFile

'**************************************************************

'Clear out all old (over 90 days old) quotes from folders.

'**************************************************************

Dir_Path = "K:\1 Operation - Gas\2 Bucket\24 Information Management\2017 Material Kitting\Adminstrative\Backup"

iMaxAge = 120 ' Set the number of days

Set oFSO = CreateObject("Scripting.FileSystemObject")

If oFSO.FolderExists(Dir_Path) Then 'Check that the folder exists

For Each oFile In oFSO.GetFolder(Dir_Path).Files

If DateDiff("d", oFile.DateLastModified, Now) > iMaxAge Then 'Look at each file to check if it is older than 120 days

oFile.Delete

End If

Next

End If

End Sub

Sub AutoDataBackup()
'***********************************************************

' AutoDataBackup

'***********************************************************

Dim backupfolder As String

On Error GoTo Fail

backupfolder = "K:\1 Operation - Gas\2 Bucket\24 Information Management\2017 Material Kitting\Adminstrative\Backup\"

ActiveWorkbook.Save

ActiveWorkbook.SaveCopyAs Filename:=backupfolder & "GRSS-" & Day(Now) & "-" & Month(Now) & "-" & Year(Now) & " " &
ActiveWorkbook.Name

ActiveWorkbook.Save

frmSucess.Show

Call DFile

Exit Sub

Fail:

frmFailure.Show

End Sub

Вам также может понравиться