Compare List and Insert if Not Found
My customer has a long list of Job Codes but only a few are used each month. He still wanted the entire list to be displayed. Another process builds the summary I I did not desire to mess with.This thing skims thru the list and if a code is not found, it makes a row and inserts it. The ߡNumbAdditsߢ is used in another process to determine where to put totals.
KLM = UBound(AbbrevArray)
BOAC = UBound(LongNameArray)
Open DataPath & "JobLists.TXT" For Output As #1
For SAS = 1 To KLM
Print #1, AbbrevArray(SAS) & vbTab & LongNameArray(SAS)
Next
Close #1
For SAS = 1 To KLM
blnFound = False
For Delta = FirstDJobSumm To lastDJobSumm
If Left(Cells(Delta, 2), 2) = AbbrevArray(SAS) Then
blnFound = True
End If
Next Delta
If blnFound = False Then
lngRow = lngRow + 1
range(Cells(Delta, 2), Cells(Delta, 14)).Select
Selection.Insert shift:=xlDown
Cells(Delta, 2) = LongNameArray(SAS)
lastDJobSumm = lastDJobSumm + 1
NumbAddits = NumbAddits + 1
End If
Next SAS
range(Cells(FirstDJobSumm, 2), Cells(lastDJobSumm, 14)).Select
Selection.Sort Key1:=range(Cells(FirstDJobSumm + 1, 2).Address), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
A special thanks to the WOPR VB/VBA Lounge and especially HansV for the nucleus of this solution.
|