Book1.rar (10.67 KB)
Sub JPM()
Dim i As Integer, j As Integer, k As Integer, l As Integer
Dim rowC As Integer
Dim rB As Range
Dim data() As String
Dim found As Boolean
'先將 AK:AR 的資料清除
Worksheets("jpm").[A2:O65536].ClearContents
'計算多少筆資料要處理
rowC = Sheets(1).Range("A1").CurrentRegion.Rows.Count
'先暫存資料,加速處理
Set rB = Sheets(1).Range(Cells(1, 1), Cells(rowC, 32))
ReDim data(rowC, 32)
k = 0
For i = 1 To rowC '處理資料
j = 1
found = False
While (j <= k) And (found = False) '比對有沒有出現過
If rB(i, 19) = data(j, 19) And rB(i, 20) = data(j, 20) And rB(i, 3) = data(j, 3) Then
found = True
data(j, 3) = rB(i, 3)
data(j, 4) = rB(i, 4)
data(j, 6) = rB(i, 6)
data(j, 19) = rB(i, 19) + "、" + rB(i, 19)
data(j, 20) = rB(i, 20) + "、" + rB(i, 20)
data(j, 21) = data(j, 21) + "、" + rB(i, 21)
data(j, 22) = data(j, 22) + "、" + rB(i, 22)
data(j, 23) = data(j, 23) + "、" + rB(i, 23)
data(j, 24) = data(j, 24) + "、" + rB(i, 24)
data(j, 25) = data(j, 25) + "、" + rB(i, 25)
data(j, 26) = data(j, 26) + "、" + rB(i, 26)
data(j, 27) = rB(i, 27)
data(j, 28) = rB(i, 28)
data(j, 29) = rB(i, 29)
data(j, 30) = rB(i, 30)
data(j, 31) = rB(i, 31)
data(j, 32) = rB(i, 32)
End If
j = j + 1
Wend
If found = False Then '沒有出現過加入新資料
k = k + 1
data(k, 3) = rB(i, 3)
data(k, 4) = rB(i, 4)
data(k, 6) = rB(i, 6)
data(k, 19) = rB(i, 19)
data(k, 20) = rB(i, 20)
data(k, 21) = rB(i, 21)
data(k, 22) = rB(i, 22)
data(k, 23) = rB(i, 23)
data(k, 24) = rB(i, 24)
data(k, 25) = rB(i, 25)
data(k, 26) = rB(i, 26)
data(k, 27) = rB(i, 27)
data(k, 28) = rB(i, 28)
data(k, 29) = rB(i, 29)
data(k, 30) = rB(i, 30)
data(k, 31) = rB(i, 31)
data(k, 32) = rB(i, 32)
End If
Next i
l = 1
For i = 1 To k '列印資料
If Range("B" & i + 1).Value = "JPM" Then
Sheets("JPM").Cells(l, 1) = data(i, 19)
Sheets("JPM").Cells(l, 2) = data(i, 20)
Sheets("JPM").Cells(l, 3) = data(i, 3)
Sheets("JPM").Cells(l, 4) = data(i, 27)
Sheets("JPM").Cells(l, 5) = data(i, 4)
Sheets("JPM").Cells(l, 6) = data(i, 28)
Sheets("JPM").Cells(l, 7) = data(i, 29)
Sheets("JPM").Cells(l, 8) = data(i, 30)
Sheets("JPM").Cells(l, 9) = data(i, 31)
Sheets("JPM").Cells(l, 10) = data(i, 32)
Sheets("JPM").Cells(l, 11) = data(i, 6)
Sheets("JPM").Cells(l, 12) = data(i, 21) + "、" + data(i, 22) + "、" + data(i, 23)
Sheets("JPM").Cells(l, 13) = data(i, 24)
Sheets("JPM").Cells(l, 14) = data(i, 25)
Sheets("JPM").Cells(l, 15) = data(i, 26)
End If
l = l + 1
Next i
MsgBox ("Sucess")
End Sub
如何可以讓不是"JPM"不顯示出來,也不會留一行空格? |