I have tried researching Microsoft's help and googling different boards but I have not been able to resolve this pesky issue. What I am doing is copying two workbooks onto the same worksheet. After the copying is compete I compare the results of the two workbooks and if I get any cells that don't match I need to post those results on another worksheet. I was testing the code and it failed on the 24th worksheet, I don't know why. I would appreciate any help.
strSrcRange = A3:AE4
strCompRange = BA3:CE4
lngRow = 3
lngCol = 5
LBound(varSrc,1 ) = 1 UBound(varComp,1 = 2
LBound(varsrc,2) = 1, UBound(varComp,2) =31
I have highlighted the line that errors in Red
Both varSrc and varComp are out of range
strSrcRange = A3:AE4
strCompRange = BA3:CE4
lngRow = 3
lngCol = 5
LBound(varSrc,1 ) = 1 UBound(varComp,1 = 2
LBound(varsrc,2) = 1, UBound(varComp,2) =31
I have highlighted the line that errors in Red
Both varSrc and varComp are out of range
Rich (BB code):
'Original
varSrc = wrkbk.Worksheets(lngShCnt).Range(strSrcRange)
varComp = wrkbk.Worksheets(lngShCnt).Range(strCompRange)
Stop
For lngRow = LBound(varSrc, 1) To UBound(varComp, 1)
For lngCol = LBound(varSrc, 2) To UBound(varComp, 2)
' 'Define ranges of Source and Compare ranges
If varSrc(lngRow, lngCol) <> varComp(lngRow, lngCol) Then
' 'Count the amount of errors
lngErrCnt = 1 + lngErrCnt
' Worksheets("Missing Tables").Columns("A:D").AutoFit
' 'Change Highlight cell in Source table with error as Red
lngRow = lngRow + 2
wrkShSrc.cells(lngRow, lngCol).Interior.ColorIndex = 3
' 'Change Highlight cell in Compare table with error as Red
If lngLastColSrc <= 26 Then lngCompLastCol = lngCol + 26
If lngLastColSrc > 26 Then lngCompLastCol = lngCol + 52
wrkShComp.cells(lngRow, lngCompLastCol).Interior.ColorIndex = 3
Application.ScreenUpdating = True
' 'Count the amount of errors
lngErrCnt = 1 + lngErrCnt
Worksheets("Missing Tables").Columns("A:C").AutoFit
' 'Change Highlight cell in Comparison table with error as Red
'' wrkShSrc.cells(lngRow, lngCol).Interior.ColorIndex = 3
' 'Change Highlight cell in Compare table with error as Red
'' lngCompLastCol = lngCol + 26
' wrkShComp.cells(lngRow, lngCompLastCol).Interior.ColorIndex = 3
' 'Define Sheet Name
strSheet = wrkShSrc.Name
With wrkShOutput
' 'Sheet Name with errors
' 'Determine Last Row of the Missing Worksheet
If lngErrCnt = 1 Then lngLastRowOutput = wrkShOutput.Range("A" & Rows.Count).End(xlUp).Row + 1
.cells(lngLastRowOutput, 1).Value = strSheet
' 'Display the sheet number
.cells(lngLastRowOutput, 2).Value = lngShCnt
' 'Get the Current Count of errors
.cells(lngLastRowOutput, 3).Value = lngErrCnt
'AutoFit Columns
Sheets("Missing Tables").Range("A:E").EntireColumn.AutoFit
Sheets("Missing Tables").Columns("B").ColumnWidth = 14
End With
With wrkShOutput.cells(lngLastRowOutput, 1).Font
.Name = "Arial"
.Size = 10
.FontStyle = "Regular"
End With
With wrkShOutput.cells(lngLastRowOutput, 2).Font
.Name = "Arial"
.Size = 10
.FontStyle = "Regular"
End With
With wrkShOutput.cells(lngLastRowOutput, 3).Font
.Name = "Arial"
.Size = 10
.FontStyle = "Regular"
End With
wrkShOutput.Columns("A:C").cells.HorizontalAlignment = xlHAlignLeft
Else
End If
Next lngCol
Next lngRow