View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default sorting by Contract #'s

I'm still confused.

It looks to me like you're sorting by contract number, then by date.

If it's the printing of the data that's a problem, maybe you could determine the
unique contract numbers, then apply data|filter|autofilter to that column. Then
filter through each unique value and print those visible rows.

I still don't understand, but maybe this will help...

Maybe...

Option Explicit
Sub testme()

Dim RngToSort As Range
Dim LastRow As Long
Dim StartCell As Range
Dim myUniqueRng As Range
Dim myCell As Range
Dim wks As Worksheet
Dim ContractCol As Long

Set wks = Worksheets("sheet1")

With wks
'remove any existing autofilter
.AutoFilterMode = False

Set StartCell = .Range("H11")
LastRow = .Cells(.Rows.Count, StartCell.Column).End(xlUp).Row
ContractCol = StartCell.Column

Set RngToSort = .Range("A11:H" & LastRow)

With RngToSort
.Cells.Sort Key1:=.Columns(ContractCol), Order1:=xlAscending, _
key2:=.Columns(2), order2:=xlAscending, _
Header:=xlYes, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End With

'advanced filter by column H (8th column in A:H)
'to get the unique list

RngToSort.Columns(ContractCol).AdvancedFilter _
action:=xlFilterInPlace, unique:=True

If RngToSort.Columns(ContractCol).Cells _
.SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
MsgBox "nothing in column A after the headers!"
Exit Sub
End If

With RngToSort.Columns(ContractCol)
'avoid the headers and just take the visible cells
Set myUniqueRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End With

For Each myCell In myUniqueRng.Cells
RngToSort.Columns(ContractCol).AutoFilter _
field:=1, Criteria1:=myCell.Value
.PrintOut preview:=True
Next myCell

'remove the autofilter from the worksheet
.AutoFilterMode = False
End With

End Sub

Earlier the contract column was column H. But in your example, it migrated back
to column A.

That makes it more confusing (to me at least).

Eric wrote:

Dave,
I hate to have you confussed. Your probably thinking that I'm some kind of
wack job so, let me try to explain what I'm doing and trying to accomplish.

First I am in Quality Control where I design and test Asphalt (roadways). I
am making a spreadsheet that I can imput all the information from each test
right into this data base I have created. We test material each day and for
different contracts (we do alot of state work). We may do 4 or 5 tests per
day and apply it to as many as 5 state contracts. We chart individual test
results and moving average of these properties. At the end of a job we must
supply charts of each test to the state authorities. The data base places
everything in cronilogical order by date. Our charts range from January to
December and we may have 50 different contracts with 200 or more tests
involved in the charts.

I want to have the accessablitliy to chart out the properties by date (which
I can do now) or by a particular contract so that I can give them to state
authorities at the end of the job

This is how it looks now. The charts for Gmm will be according to date (7-7
through 7-9) and this chart will represent the material for 3 days and 3
different contracts.

contract # Date Gmm Gse Gsa etc.....
1. 123 7/7 2.569 2.897 2.987
2. 698 7/8 2.587 2.901 2.999
3. 123 7/8 2.569 2.994 2.999
4. 456 7/9 " " "
5. 123 7/9

I now want it to be like the following: I finished Contract 123 so I need
to print its charts with out the other contracts so.....

contract # Date Gmm Gse Gsa etc.....
1. 123 7/7 2.569 2.897 2.987
2. 123 7/8 2.569 2.994 2.999
3. 123 7/9
4. 698 7/8 2.587 2.901 2.999
5. 456 7/9 " " "

My spreadsheet only prints from #1 first. This is why I need to manipulate
the contract #'s. I hope this makes more sense. Please give me another
chance. I am desperate to get this thing working.

Eric

<<snipped
--

Dave Peterson