2013-05-09 40 views

回答

1

我認爲這將工作...根據寬度可能不得不修改列。

Private Sub CompareSheets() 
Dim first_index As Integer 
Dim last_index As Integer 
Dim sheet1 As Worksheet 
Dim sheet2 As Worksheet 
Dim r1 As Integer 
Dim r2 As Integer 
Dim found As Boolean 

Set sheet1 = Worksheets(1) 
Set sheet2 = Worksheets(2) 

Application.ScreenUpdating = False 

first_index = 1 
last_index = sheet1.Range("a" & Rows.Count).End(xlUp).Row 

For r2 = first_index To last_index 
    found = False 
    For r1 = first_index To last_index 
     If sheet1.Cells(r1, 16) = sheet2.Cells(r2, 9) Then 
     ' Found match. 
      found = True 
      Exit For 
     End If 
    Next r1 


    If Not found Then 
     ' Do something if the if we did not find it??? 
    End If 
Next r2 

Application.ScreenUpdating = True 

End Sub 
+0

@ dirtyw0lf如果您發現此接受請點擊大型向下箭頭爲「接受」這一點,那麼你可以點擊朝上的箭頭,表明它是有益的,如果你的願望。謝謝... – Jim 2013-05-09 15:56:38

+0

對於last_index = sheet1.Range(「a」&Rows.Counatb).End(xlUp).Row,您運行的是什麼版本的excel? – dirtyw0lf 2013-05-13 15:04:47

+0

@ dirtyw0lf 2010 ...什麼是錯誤? – Jim 2013-05-13 18:33:55