I use following
vb macro.
this macro give output in Excel file.
My problem in line no 20 and 21 (or loop)
when IP No. not found it should save in ipnotfound sheet how ?
Sub MTPVolDataSort()
a = 3
Sheets("emme2").Select
Do Until IsEmpty(Cells(a, 1)) = True
vfrnode = Cells(a, 1)
vfr = Right(vfrnode, 1)
Dim vfrchk1 As Variant
vfrchk1 = Array("2", "4", "6", "8")
For i = 0 To 3
If vfr = vfrchk1(i) Then GoTo 110
Next i
GoTo 120
110 nnumfr = Cells(a, 1)
nodenumfr = Left(nnumfr, 4)
nodenumfr = CInt(nodenumfr)
GoTo 130
120 nnumfr = Cells(a, 1)
nodenumfr = Left(nnumfr, 4)
nodenumfr = CInt(nodenumfr)
nnumto = Cells(a, 2)
nodenumto = Left(nnumto, 4)
nodenumto = CInt(nodenumto)
GoTo 140
130 b = 2
Sheets("ipno").Select
Do Until IsEmpty(Cells(b, 1)) = True
If Cells(b, 1) = nodenumfr Then GoTo 10 Else GoTo 21
140 b = 2
Sheets("ipno").Select
Do Until IsEmpty(Cells(b, 1)) = True
If Cells(b, 1) = nodenumfr And Cells(b, 2) = nodenumto Then GoTo 10 Else GoTo 20
10 ipno = Cells(b, 3)
Sheets("output").Select
c = 3
11 If Cells(c, 2) = ipno Then GoTo 14
If Cells(c, 2) = emptystring Then Cells(c, 2) = ipno Else GoTo 12
GoTo 14
12 c = c + 1
GoTo 11
14 Sheets("emme2").Select
vfrnode = Cells(a, 1)
vfr = Right(vfrnode, 1)
Dim vfrchk2 As Variant
vfrchk2 = Array("2", "4", "6", "8")
For i = 0 To 3
If vfr = vfrchk2(i) Then GoTo 150
Next i
GoTo 160
150 nnfr = Left(Cells(a, 1), 4)
nnfr = CInt(nnfr)
Do While nodenumfr = nnfr
vfrnode = Cells(a, 1)
vfr = Right(vfrnode, 1)
Dim vfrchk3 As Variant
vfrchk3 = Array("2", "4", "6", "8")
For i = 0 To 3
If vfr = vfrchk3(i) Then GoTo 70
Next i
GoTo 80
160 nnfr = Left(Cells(a, 1), 4)
nnfr = CInt(nnfr)
nnto = Left(Cells(a, 2), 4)
nnto = CInt(nnto)
Do While nodenumfr = nnfr And nodenumto = nnto
vfrnode = Cells(a, 1)
vfr = Right(vfrnode, 1)
Dim vfrchk4 As Variant
vfrchk4 = Array("2", "4", "6", "8")
For i = 0 To 3
If vfr = vfrchk4(i) Then GoTo 70
Next i
GoTo 80
70 vol = Cells(a, 3)
Sheets("ipno").Select
d = 23
Do Until IsEmpty(Cells(d, 5)) = True
If Cells(d, 5) = vfr Then mov = Cells(d, 7) Else GoTo 30
Sheets("output").Select
e = 3
Do Until IsEmpty(Cells(2, e)) = True
If Cells(2, e) = mov Then GoTo 71 Else GoTo 40
71 If Cells(c, e) = emptystring Then Cells(c, e) = vol
GoTo 170
40 e = e + 1
Loop
Sheets("output").Select
Dim msg3, style3, title3
msg3 = "(Movement not specified in output + str(style3), str(title3)) "
style3 = vbOKOnly
title3 = Cells(c, 2)
response = MsgBox(msg3, style3, title3)
End
80 vtonode = Cells(a, 2)
vto = Right(vtonode, 1)
vol = Cells(a, 3)
Sheets("ipno").Select
d = 2
Do Until IsEmpty(Cells(d, 5)) = True
If Cells(d, 5) = vfr And Cells(d, 6) = vto Then mov = Cells(d, 7) Else GoTo 31
Sheets("output").Select
e = 3
Do Until IsEmpty(Cells(2, e)) = True
If Cells(2, e) = mov Then GoTo 81 Else GoTo 41
81 If Cells(c, e) = emptystring Then Cells(c, e) = vol
GoTo 170
41 e = e + 1
Loop
Sheets("output").Select
Dim msg1, style1, title1
msg1 = "Movement not specified in output"
style1 = vbOKOnly
title1 = Cells(c, 2)
response = MsgBox(msg1, style1, title1)
End
31 d = d + 1
Loop
Sheets("output").Select
Dim msg, style, title
msg = "Movement code not found"
style = vbOKOnly
title = Cells(c, 2)
response = MsgBox(msg, style, title)
End
30 d = d + 1
Loop
Sheets("output").Select
Dim msg2, style2, title2
msg2 = "Movement code not found"
style2 = vbOKOnly
title2 = Cells(c, 2)
response = MsgBox(msg2, style2, title2)
End
170 Sheets("emme2").Select
a = a + 1
If Cells(a, 1) = emptystring Then End
vfrnode = Cells(a, 1)
vfr = Right(vfrnode, 1)
Dim vfrchk5 As Variant
vfrchk5 = Array("2", "4", "6", "8")
For i = 0 To 3
If vfr = vfrchk5(i) Then GoTo 61
Next i
GoTo 60
60 Sheets("emme2").Select
nnfr = Left(Cells(a, 1), 4)
nnfr = CInt(nnfr)
nnto = Left(Cells(a, 2), 4)
nnto = CInt(nnto)
Loop
GoTo 50
61 Sheets("emme2").Select
nnfr = Left(Cells(a, 1), 4)
nnfr = CInt(nnfr)
Loop
GoTo 50
20 b = b + 1
Loop
MsgBox ("IP No. not found, please check the list" + Str(nodenumfr) + Str(nodenumto)) // if ipno not found
//it save ipno in ipnotfound sheet
// how ?
' Sheets("ipnotfound").Select
End
21 b = b + 1
Loop
MsgBox ("IP No. not found, please check the list" + Str(nodenumfr) + Str(nodenumto)) //if ipno not found
//it save ipno in ipnotfound sheet
// how ?
' Sheets("ipnotfound").Select
End
50 Sheets("emme2").Select
Loop
Sheets("output").Select
End Sub
regards.
Mateen