Hi everyone,
Can anyone tell what is wrong with the following If in For? The macro would not resume the Next bit - the if works just fine but only the first row is investigated then the execution terminates without ever getting to the second row.
'First complex If - see Decision Tree tab
Sheets("Shipment Table").Select
ActiveSheet.Range(Range("A1"), Cells.SpecialCells(xlCellTypeLastCell)).AutoFilter Field:=4, Criteria1:="100.0000%"
Sheets("Shipment Table").Select
ActiveSheet.Cells(1, 1).CurrentRegion.Select
nrLines = Selection.Rows.Count
For s = 2 To nrLines
If ActiveSheet.Cells(s, 2).Value = ActiveSheet.Cells(s, 3).Value Then
If ActiveSheet.Cells(s, 6).Value = "" Then
If ActiveSheet.Cells(s, 7).Value = "" Then
ActiveSheet.Rows(s).Select
Selection.EntireRow.Delete
Else
ActiveSheet.Rows(s).EntireRow.Select
Selection.Copy
Sheets("Unload").Activate
If ActiveSheet.Cells(2, 1).Value <> 0 Then
ActiveSheet.Cells(1, 1).CurrentRegion.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Else
Sheets("Unload").Cells(1, 1).Select
ActiveCell.Offset(1, 0).Select
End If
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Else
ActiveSheet.Rows(s).EntireRow.Select
Selection.Copy
Sheets("Investigate").Activate
If ActiveSheet.Cells(2, 1).Value <> 0 Then
ActiveSheet.Cells(1, 1).CurrentRegion.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Else
Sheets("Investigate").Cells(1, 1).Select
ActiveCell.Offset(1, 0).Select
End If
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Else
If ActiveSheet.Cells(s, 3).Value = 0 Then
ActiveSheet.Rows(s).EntireRow.Select
Selection.Copy
Sheets("Import").Activate
If ActiveSheet.Cells(2, 1).Value <> 0 Then
ActiveSheet.Cells(1, 1).CurrentRegion.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Else
Sheets("Import").Cells(1, 1).Select
ActiveCell.Offset(1, 0).Select
End If
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Else
ActiveSheet.Rows(s).EntireRow.Select
Selection.Copy
Sheets("Investigate").Activate
If ActiveSheet.Cells(2, 1).Value <> 0 Then
ActiveSheet.Cells(1, 1).CurrentRegion.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Else
Sheets("Investigate").Cells(1, 1).Select
ActiveCell.Offset(1, 0).Select
End If
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
End If
Next s
Sheets("Shipment Table").Select
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
Please help! I have been looking at this for a while and just cannot figure it out...
Thanks a lot,
Alex
Can anyone tell what is wrong with the following If in For? The macro would not resume the Next bit - the if works just fine but only the first row is investigated then the execution terminates without ever getting to the second row.
'First complex If - see Decision Tree tab
Sheets("Shipment Table").Select
ActiveSheet.Range(Range("A1"), Cells.SpecialCells(xlCellTypeLastCell)).AutoFilter Field:=4, Criteria1:="100.0000%"
Sheets("Shipment Table").Select
ActiveSheet.Cells(1, 1).CurrentRegion.Select
nrLines = Selection.Rows.Count
For s = 2 To nrLines
If ActiveSheet.Cells(s, 2).Value = ActiveSheet.Cells(s, 3).Value Then
If ActiveSheet.Cells(s, 6).Value = "" Then
If ActiveSheet.Cells(s, 7).Value = "" Then
ActiveSheet.Rows(s).Select
Selection.EntireRow.Delete
Else
ActiveSheet.Rows(s).EntireRow.Select
Selection.Copy
Sheets("Unload").Activate
If ActiveSheet.Cells(2, 1).Value <> 0 Then
ActiveSheet.Cells(1, 1).CurrentRegion.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Else
Sheets("Unload").Cells(1, 1).Select
ActiveCell.Offset(1, 0).Select
End If
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Else
ActiveSheet.Rows(s).EntireRow.Select
Selection.Copy
Sheets("Investigate").Activate
If ActiveSheet.Cells(2, 1).Value <> 0 Then
ActiveSheet.Cells(1, 1).CurrentRegion.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Else
Sheets("Investigate").Cells(1, 1).Select
ActiveCell.Offset(1, 0).Select
End If
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Else
If ActiveSheet.Cells(s, 3).Value = 0 Then
ActiveSheet.Rows(s).EntireRow.Select
Selection.Copy
Sheets("Import").Activate
If ActiveSheet.Cells(2, 1).Value <> 0 Then
ActiveSheet.Cells(1, 1).CurrentRegion.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Else
Sheets("Import").Cells(1, 1).Select
ActiveCell.Offset(1, 0).Select
End If
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Else
ActiveSheet.Rows(s).EntireRow.Select
Selection.Copy
Sheets("Investigate").Activate
If ActiveSheet.Cells(2, 1).Value <> 0 Then
ActiveSheet.Cells(1, 1).CurrentRegion.Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Else
Sheets("Investigate").Cells(1, 1).Select
ActiveCell.Offset(1, 0).Select
End If
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
End If
Next s
Sheets("Shipment Table").Select
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
Please help! I have been looking at this for a while and just cannot figure it out...
Thanks a lot,
Alex