Sub 派車表_輸入()
Dim DD, CC$, Arr, Brr, i&, j%, N&, xD
Call 派車表_清除
DD = [D1]: CC = [B1]
If Not IsDate(DD) Then MsgBox "**請輸入日期!! ": Exit Sub
If CC = "" Then MsgBox "**請輸入[車編]!! ": Exit Sub
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([工作表2!L1], [工作表2!A65536].End(xlUp))
ReDim Brr(1 To UBound(Arr), 1 To 4)
For i = 2 To UBound(Arr)
If Arr(i, 12) <> DD Or Arr(i, 10) <> CC Then GoTo 101
PNo = Arr(i, 11): If xD(PNo) = 1 Then GoTo 101
xD(PNo) = 1: N = N + 1: Arr(N, 2) = Format(N, "00") '有資料時Arr的第2欄位,自動產生序號
For j = 1 To 4
Brr(N, 1) = Arr(i, 1)
Brr(N, 3) = Arr(i, 2)
Brr(N, 2) = Arr(N, 2)
Next j
Brr(N, 4) = Arr(i, 11)
101: Next i
If N = 0 Then MsgBox "**沒有符合的資料!! ": Exit Sub
With Sheets("工作表1")
.[A3].Resize(N, UBound(Brr, 2)) = Brr
.Range("A1:G" & N + 3).Name = "'" & .Name & "'!Print_Area"
.Range("1:3").Name = "'" & .Name & "'!Print_Titles"
End With
End Sub
[attach]33376[/attach]作者: samwang 時間: 2021-6-4 19:45
Sub 派車表_輸入1()
Dim DD, CC$, Arr, Brr, i&, j%, N&, xD
Call 派車表_清除
DD = [D1]: CC = [B1]
If Not IsDate(DD) Then MsgBox "**請輸入日期!! ": Exit Sub
If CC = "" Then MsgBox "**請輸入[車編]!! ": Exit Sub
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([工作表2!L1], [工作表2!A65536].End(xlUp))
ReDim Brr(1 To UBound(Arr), 1 To 4)
For i = 2 To UBound(Arr)
If Arr(i, 12) <> DD Or Arr(i, 10) <> CC Then GoTo 101
PNo = Arr(i, 11): If xD(PNo) = 1 Then GoTo 101
xD(PNo) = 1: N = N + 1
If InStr(Arr(i, 2), "A") Then
Brr(N, 2) = Format(Right(Arr(i, 2), 2), "00")
Else
Brr(N, 2) = Format(Mid(Right(Arr(i, 2), 3), 1, 2), "00")
End If
Brr(N, 1) = Arr(i, 1)
Brr(N, 3) = Arr(i, 2)
Brr(N, 4) = Arr(i, 11)
101: Next i
If N = 0 Then MsgBox "**沒有符合的資料!! ": Exit Sub
With Sheets("工作表1")
.[A3].Resize(N, UBound(Brr, 2)) = Brr
.Range("A1:G" & N + 3).Name = "'" & .Name & "'!Print_Area"
.Range("1:3").Name = "'" & .Name & "'!Print_Titles"
End With
End Sub作者: BV7BW 時間: 2021-6-4 19:51
Sub 派車表_輸入()
Dim DD, CC$, Arr, Brr, i&, j%, N&, xD
Call 派車表_清除
DD = [D1]: CC = [B1]
If Not IsDate(DD) Then MsgBox "**請輸入日期!! ": Exit Sub
If CC = "" Then MsgBox "**請輸入[車編]!! ": Exit Sub
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([工作表2!L1], [工作表2!A65536].End(xlUp))
ReDim Brr(1 To UBound(Arr), 1 To 4)
For i = 2 To UBound(Arr)
If Arr(i, 12) <> DD Or Arr(i, 10) <> CC Then GoTo 101
PNo = Arr(i, 11): If xD(PNo) = 1 Then GoTo 101
xD(PNo) = 1
N = N + 1
For j = 1 To 4
Brr(N, 1) = Arr(i, 1)
SS$ = Replace(Arr(i, 2), "S", "")
Brr(N, 2) = Right(SS, 2)
Brr(N, 3) = Arr(i, 2)
Next j
Brr(N, 4) = Arr(i, 11)
101: Next i
If N = 0 Then MsgBox "**沒有符合的資料!! ": Exit Sub
With Sheets("工作表1")
.[A3].Resize(N, UBound(Brr, 2)) = Brr
.Range("A1:G" & N + 3).Name = "'" & .Name & "'!Print_Area"
.Range("1:3").Name = "'" & .Name & "'!Print_Titles"
End With
Columns("B").NumberFormatLocal = "00"
End Sub作者: samwang 時間: 2021-6-8 13:46
Sub 派車表_輸入2()
Dim DD, CC$, Arr, Brr, i&, j%, N&, xD
Call 派車表_清除
DD = [D1]: CC = [B1]
If Not IsDate(DD) Then MsgBox "**請輸入日期!! ": Exit Sub
If CC = "" Then MsgBox "**請輸入[車編]!! ": Exit Sub
Set xD = CreateObject("Scripting.Dictionary")
Arr = Range([工作表2!L1], [工作表2!A65536].End(xlUp))
ReDim Brr(1 To UBound(Arr), 1 To 4)
For i = 2 To UBound(Arr)
If Arr(i, 12) <> DD Or Arr(i, 10) <> CC Then GoTo 101
PNo = Arr(i, 11): If xD(PNo) = 1 Then GoTo 101
xD(PNo) = 1: N = N + 1
If InStr(Arr(i, 2), "S") Then
Brr(N, 2) = Mid(Split(Arr(i, 2), "-")(1), 1, Len(Split(Arr(i, 2), "-")(1)) - 1)
Else
Brr(N, 2) = Split(Arr(i, 2), "-")(1)
End If
Brr(N, 1) = Arr(i, 1)
Brr(N, 3) = Arr(i, 2)
Brr(N, 4) = Arr(i, 11)
101: Next i
If N = 0 Then MsgBox "**沒有符合的資料!! ": Exit Sub
With Sheets("工作表1")
.[A3].Resize(N, UBound(Brr, 2)) = Brr
.Range("A1:G" & N + 3).Name = "'" & .Name & "'!Print_Area"
.Range("1:3").Name = "'" & .Name & "'!Print_Titles"
End With
End Sub作者: BV7BW 時間: 2021-6-9 12:51