View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
NoodNutt[_2_] NoodNutt[_2_] is offline
external usenet poster
 
Posts: 39
Default Nested For statements

Hi Garry

There is definitely added weight to my wife's needling in that I am guilty of assuming people just understand instantly what I am banging on about, for this I must apologise.

Let me restart by stating that the existing codes work really well, but it creates all route sheets; I want the user to have the option to exclude any route.
It's my fault your code did not work as I failed to include the module3 codes that do the important stuff which would have given you a clearer insight in understanding what they do to generate these route sheets.

I was hoping to have the user look thru the "Fleet Summary" sheet first, selecting the routes he/she wants to actually include in the route sheet creation phase as each day will be different; most, if not all routes will be included in the EDI (Download File), but one or two may not be able to be covered due to driver absenteeism or vehicle mechanical issues.

Function testRouteSheetorAdd(tSheet As String) As Boolean

found = False

For Each wksheet In ActiveWorkbook.Sheets

If wksheet.Name = tSheet Then
testRouteSheetorAdd = True
found = True
Exit For
End If

Next wksheet

If found = False Then
Sheets("TEMPLATE").Copy after:=Sheets(Sheets.Count)
actSheet = ActiveSheet.Name
Sheets(actSheet).Name = tSheet
Range("A1:B3").Select
ActiveCell.FormulaR1C1 = tSheet
testRouteSheetorAdd = True
End If

End Function

Sub TansferCommittedRoute(nSheet As String, rw As Integer)

Sheets("Conversion").Select
tLoad = Sheets("Conversion").Range("A" & rw).Value

For j = 8 To 69
cLoad = Sheets(nSheet).Range("A" & j).Value

If cLoad = "" Then
If Application.WorksheetFunction.CountA(Worksheets(nS heet).Range("A" & j & ":A" & j + 50)) = 0 Then

'Transfer the Route Ref
Worksheets(nSheet).Range("A" & j).Value = Format(Sheets("Conversion").Range("B" & rw).Value, "00")
'Shipment Custom
Worksheets(nSheet).Range("B" & j).Value = Sheets("Conversion").Range("C" & rw).Value
'Customer Name
Worksheets(nSheet).Range("C" & j).Value = Sheets("Conversion").Range("D" & rw).Value
'Address
Worksheets(nSheet).Range("D" & j).Value = Sheets("Conversion").Range("E" & rw).Value
'Suburb/City
Worksheets(nSheet).Range("E" & j).Value = Sheets("Conversion").Range("F" & rw).Value
'Arrival Time
Worksheets(nSheet).Range("F" & j).Value = Sheets("Conversion").Range("G" & rw).Value
'Time on Site
Worksheets(nSheet).Range("G" & j).Value = Sheets("Conversion").Range("H" & rw).Value
'Departure Time
Worksheets(nSheet).Range("H" & j).Value = Sheets("Conversion").Range("I" & rw).Value

qty = Sheets("Conversion").Range("J" & rw).Value
Worksheets(nSheet).Range("I" & j).Value = qty
'Transfer WEight
wght = Sheets("Conversion").Range("K" & rw).Value
Worksheets(nSheet).Range("J" & j).Value = wght

'Special
Worksheets(nSheet).Range("K" & j).Value = Sheets("Conversion").Range("M" & rw).Value

'Transfer the Route Ref
Worksheets(nSheet).Range("A" & j + 1).Value = Format(Sheets("Conversion").Range("B" & rw).Value, "00")
'Time Window Label
Worksheets(nSheet).Range("B" & j + 1).Value = "Time Window:"
Worksheets(nSheet).Range("B" & j + 1).Font.Bold = True
'Time Window Instructions
Worksheets(nSheet).Range("C" & j + 1).Value = Sheets("Conversion").Range("L" & rw).Value
'Customer Note Label
Worksheets(nSheet).Range("E" & j + 1).Value = "Customer Notes:"
Worksheets(nSheet).Range("E" & j + 1).Font.Bold = True
'Customer Note Instructions
Worksheets(nSheet).Range("F" & j + 1).Value = Sheets("Conversion").Range("N" & rw).Value
Exit For

End If
End If

If tLoad = cLoad Then
MsgBox ("Load already exists, error?")
End If
Next j

sortFunc = "A"
'Sort the new sheet so that ref's are grouped
Sheets(nSheet).Select
Range("A8:K" & j).Select
Selection.Sort Key1:=Range(sortFunc & "8"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Range("A8:K" & j + 1).Select
Selection.Sort Key1:=Range(sortFunc & "8"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal

'add values to Fleet Summary Sheet
For i = 5 To 50
If Sheets("FLEET SUMMARY").Range("A" & i).Value = nSheet Then
Sheets("FLEET SUMMARY").Range("C" & i).Value = Sheets("FLEET SUMMARY").Range("C" & i).Value + qty
Sheets("FLEET SUMMARY").Range("D" & i).Value = Sheets("FLEET SUMMARY").Range("D" & i).Value + wght
Exit For
End If
Next i

End Sub

These codes were in an existing application created by another programmer (no longer with the company) many, many years ago for a contract; I have been using and modifying it ever since; And even though the code is doing exactly the same thing for this new project, the data and structure is different, which is why I would like the user to have some flexibility with it.

Thank you again
Cheers
Mark.