2013-05-09 2 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

+0

получение ошибки для last_index = sheet1.Range ("a" & Rows.Counatb) .End (xlUp). Как вы работаете над версией excel? – dirtyw0lf

+0

@ dirtyw0lf 2010 ... Какая ошибка? – Jim

Смежные вопросы