Attribute VB_Name = "check" Global file名1 As String Global file名2 As String Dim ed() As Boolean Sub ダブルチェック() nbooks = Workbooks.Count If nbooks <> 2 Then If nbook > 2 Then MsgBox ("bookの数が" + Str(nbooks) + "です。一度excelを終了させてから改めて2つファイルを開いてください。") End Else MsgBox ("bookの数が" + Str(nbooks) + "です。もう一つのファイルも開いてください。 ") End End If End If file名1 = Workbooks(1).Name '"Book1.xls" file名2 = Workbooks(2).Name Call file1(1, 1) With ActiveSheet.UsedRange '対象はアクティブシートの使用中のセル '最終行の行番号 行数 = .Rows(.Rows.Count).Row '最終列の列番号 桁数 = .Columns(.Columns.Count).Column End With check1 = False Call file1(1, 1) Range(Cells(1, 1), Cells(行数, 桁数)).Select With Selection.Interior Selection.Interior.ColorIndex = xlNone End With d1 = Range(Cells(1, 1), Cells(行数, 桁数)).Value Call file2(1, 1) Range(Cells(1, 1), Cells(行数, 桁数)).Select With Selection.Interior Selection.Interior.ColorIndex = xlNone End With d2 = Range(Cells(1, 1), Cells(行数, 桁数)).Value ReDim ed(行数, 桁数) As Boolean ii = 1 jj = 1 For i = 1 To 行数 For j = 1 To 桁数 ed(i, j) = False If d1(i, j) <> d2(i, j) Then ed(i, j) = True check1 = True nerror = nerror + 1 If ii = 1 And jj = 1 Then ii = i jj = j End If End If Next j Next i If check1 Then Call file1(ii, jj) For i = 1 To 行数 For j = 1 To 桁数 If ed(i, j) Then Call ecolor(i, j) End If Next j Next i Call file2(ii, jj) For i = 1 To 行数 For j = 1 To 桁数 If ed(i, j) Then Call ecolor(i, j) End If Next j Next i Call file1(ii, jj) Call file2(ii, jj) MsgBox (Str(nerror) + "カ所 相違がありました。") Else MsgBox ("完成!! おめでとう") End If End Sub Private Sub ecolor(a, b) Range(Cells(a, b), Cells(a, b)).Select With Selection.Interior .ColorIndex = 7 .Pattern = xlSolid .PatternColorIndex = xlAutomatic End With End Sub Private Sub clearcolor(a, b) With Selection.Interior Selection.Interior.ColorIndex = xlNone End With End Sub Private Sub file1(a, b) Workbooks(file名1).Activate Sheets("sheet1").Select Range(Cells(a, b), Cells(a, b)).Select End Sub Private Sub file2(a, b) Workbooks(file名2).Activate Sheets("sheet1").Select Range(Cells(a, b), Cells(a, b)).Select End Sub