Access.2007.VBA.Bibl..

(John Hannent) #1
wks.Range(strDataRange).Select
wks.Sort.SortFields.Clear
wks.Sort.SortFields.Add Key:=Range(strKey1Range), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
wks.Sort.SortFields.Add Key:=Range(strKey2Range), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
With wks.Sort
.SetRange Range(strDataRange)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Remove the duplicate countries:

Set rng = wks.Range(“A:A”)
For i = 4 To lngRows
Debug.Print rng.Cells(i, 1).Address & “ contains “ _
& rng.Cells(i, 1).Value
If rng.Cells(i, 1) = rng.Cells(i - 1, 1) Then
rng.Cells(i, 1).Font.ColorIndex = 2
ElseIf rng.Cells(i, 1).Value <> strCountry Then
Debug.Print “Different data in “ _
& rng.Cells(i, 1).Address
strCountry = rng.Cells(i, 1).Value
End If
Next i

Remove the duplicate categories:

Set rng = wks.Range(“B:B”)
For i = 4 To lngRows
Debug.Print rng.Cells(i, 1).Address & “ contains “ _
& rng.Cells(i, 1).Value
If rng.Cells(i, 1).Value = rng.Cells(i - 1, 1) Then
rng.Cells(i, 1).Font.ColorIndex = 2
ElseIf rng.Cells(i, 1).Value <> strCategory Then
Debug.Print “Different data in “ _
& rng.Cells(i, 1).Address
strCategory = rng.Cells(i, 1).Value
End If
Next i

Part I The Office Components and What They Do Best

Free download pdf