0
我有以下表,我想複製的行如果訂單ID和合同是一樣的多列基於重複的值複製行
a busy cat http://i57.tinypic.com/2qta42b.jpg
我想獲得宏要做到這一點:
a busy cat http://i59.tinypic.com/2vdfc0i.png
難道你們給我推到正確的方向來做到這一點?在此先感謝
我有以下表,我想複製的行如果訂單ID和合同是一樣的多列基於重複的值複製行
a busy cat http://i57.tinypic.com/2qta42b.jpg
我想獲得宏要做到這一點:
a busy cat http://i59.tinypic.com/2vdfc0i.png
難道你們給我推到正確的方向來做到這一點?在此先感謝
可以使此代碼更EFFIENT,但這是「推到正確的方向來完成這個」 :)
Sub myMacro()
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' decleration
Dim rowData As Integer, rowNew As Integer
rowData = 1
rowNew = 1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' put first two entries
Range("H" & rowNew, "J" & rowNew).Value = Range("A" & rowData, "C" & rowData).Value
rowNew = rowNew + 1
rowData = rowData + 1
Range("H" & rowNew, "J" & rowNew).Value = Range("A" & rowData, "C" & rowData).Value
rowNew = rowNew + 1
rowData = rowData + 1
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' loop through all of column A entries
Do While Range("A" & rowData).Value <> ""
' similar entry found
If Range("A" & rowData).Value = Range("A" & rowData - 1).Value Then
Range("H" & rowNew, "J" & rowNew).Value = Range("A" & rowData, "C" & rowData).Value
rowNew = rowNew + 1
rowData = rowData + 1
' similar entry Not found
Else
rowNew = rowNew + 1
Range("H" & rowNew, "J" & rowNew).Value = Range("A1:C1").Value
rowNew = rowNew + 1
Range("H" & rowNew, "J" & rowNew).Value = Range("A" & rowData, "C" & rowData).Value
rowNew = rowNew + 1
rowData = rowData + 1
End If
Loop
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
我在這裏看不到任何情況下他們在哪裏。你是不是說'124'中'24'的最後兩位數字與'6CV4 P0924'中'24'的最後兩位數字相符? – 2014-09-04 17:14:09
對不起,我的意思是說如果有類似的訂單ID和類似的合同,然後複製行。所以,在上面的例子中,我們有5行,其中訂單ID = 111和合約= 6CU4 P0920。可能會出現這種情況,即您擁有相同的訂單ID但合同不同(例如,對於Order ID爲111的新行上面的示例,創建Contract = 6CU4 P1922)。在這種情況下,這個新行將與其他5行分開 – user1753675 2014-09-04 17:16:42
什麼構成類似?你有沒有嘗試過任何東西?任何代碼開始? – 2014-09-04 17:18:30