我正在寫一個工作在excel中的宏,我遇到了麻煩。在這種情況下,有兩張表,「BU」和「TOPS信息」。當使用宏時,應該搜索「BU」的每一行以獲得「TOPS Information」中找到的值,然後進入「TOPS Information」的下一行並重復該過程。如果找到了正確的匹配,複製單元格並將其粘貼到「TOPS信息」VBA循環/邏輯問題
這裏是代碼:
Sub QIM()
Dim j As Integer
Dim k As Integer
Dim i As Integer
Dim l As Integer
Dim m As Integer
Dim searchArray(1 To 3) As String
j = 0
k = 1
'WARNING: Temporary Sheet Names
lastRowTOPS = Worksheets("TOPS Information").Cells(Rows.Count, "A").End(xlUp).Row
lastRowBU = Worksheets("BU").Cells(Rows.Count, "A").End(xlUp).Row
'Cycle through BU rows
For j = lastRowTOPS To 1 Step -1
'Cycle through searchArray for each BU row
For k = lastRowBU To 1 Step -1
'//////////////////////////////////////
x = Sheets("BU").Range("B" & k).Value
y = Range("C" & j).Value
If StrComp(x, y) = 1 Then
Sheets("BU").Range("C" & k).Copy
Range("H" & j).PasteSpecial
End If
'//////////////////////////////////////
Next k
Next j
End Sub
這如果「TOPS信息」在時間選擇的任何和所有幫助將宏顯然只適用。感謝!感謝!
[http://office.microsoft.com/en-us/excel-help/vlookup-HP005209335.aspx](vlookup)可能是你在找什麼 – Alex
斷開的鏈接。 [vlookup](http://office.microsoft.com/en-us/excel-help/vlookup-HP005209335.aspx) –
http://office.microsoft.com/en-us/excel-help/vlookup-HP005209335 .aspx Thanks @JimmySmith – Alex