C
Caveman1957
I am receiving the runtime error 13 message on
this line of code
If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) And UCase(CUCM.Cells(CUCMSourceRow, 2)
= UCase(ALIR.Cells(MainLoop, 14)) And (UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 12))) Then
the entire code this is from is
Sub Button1_Click()
Dim LastRow As Long
Dim LastResultRow As Long
Dim DestinationRow As Long
Dim ALIRSourceRow As Long
Dim CUCMSourceRow As Long
Dim MainLoop As Long
LastRow = ALIR.UsedRange.Rows.Count
DestinationRow = 3
ALIRSourceRow = 2
CUCMSourceRow = 2
MatchType = 0
LastResultRow = Results.UsedRange.Rows.Count
Results.Range(Cells(3, 1), Cells(LastRow, 9)).ClearContents
Results.Range(Cells(3, 1), Cells(LastRow, 9)).Interior.ColorIndex = 0
Do While CUCM.Cells(CUCMSourceRow, 3) <> ""
For MainLoop = 2 To LastRow
'If match all then MatchType = 1
If CUCM.Cells(CUCMSourceRow, 5) = Right(ALIR.Cells(MainLoop
32), 10) Then
MatchType = 3
ALIRSourceRow = MainLoop
'If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) Then
'If UCase(CUCM.Cells(CUCMSourceRow, 2))
UCase(ALIR.Cells(MainLoop, 14)) Then
'If UCase(CUCM.Cells(CUCMSourceRow, 1))
UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow, 1))
UCase(ALIR.Cells(MainLoop, 12)) Then
If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) And UCase(CUCM.Cells(CUCMSourceRow, 2)
= UCase(ALIR.Cells(MainLoop, 14)) And (UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 12))) Then
MatchType = 1
Call WriteRow(MainLoop, CUCMSourceRow, DestinationRow
MatchType)
DestinationRow = DestinationRow + 1
Exit For
Else
Call WriteRow(MainLoop, CUCMSourceRow, DestinationRow
MatchType)
DestinationRow = DestinationRow + 1
Exit For
End If
Else
'If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) Then
'If UCase(CUCM.Cells(CUCMSourceRow, 2))
UCase(ALIR.Cells(MainLoop, 14)) Then
'If UCase(CUCM.Cells(CUCMSourceRow, 1))
UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow, 1))
UCase(ALIR.Cells(MainLoop, 12)) Then
If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) And UCase(CUCM.Cells(CUCMSourceRow, 2)
= UCase(ALIR.Cells(MainLoop, 14)) And (UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 12))) Then
MatchType = 2
Call WriteRow(MainLoop, CUCMSourceRow, DestinationRow
MatchType)
DestinationRow = DestinationRow + 1
Exit For
End If
End If
Next MainLoop
CUCMSourceRow = CUCMSourceRow + 1
MatchType = 5
Loop
End Sub
Function WriteRow(ByVal ALIRSourceRow As Long, _
ByVal CUCMSourceRow As Long, _
ByVal DestinationRow As Long, _
ByVal MatchType As Integer)
Dim ALIRSourceCol(1 To 2) As Integer
Dim CUCMSourceCol(1 To 5) As Integer
Dim LoopCount As Integer
Dim GREEN As Integer
Dim YELLOW As Integer
Dim ORANGE As Integer
Dim BLUE As Integer
ALIRSourceCol(1) = 21 'Principal Country Location
ALIRSourceCol(2) = 28 'Unique Key
CUCMSourceCol(1) = 1 'First Name
CUCMSourceCol(2) = 2 'Last Name
CUCMSourceCol(3) = 3 'User ID
CUCMSourceCol(4) = 4 'Department
GREEN = 43
YELLOW = 6
ORANGE = 45
BLUE = 23
For LoopCount = 1 To 4
CUCM.Cells(CUCMSourceRow, CUCMSourceCol(LoopCount)).Copy
Results.Cells(DestinationRow, LoopCount).PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Next LoopCount
For LoopCount = 1 To 2
ALIR.Cells(ALIRSourceRow, ALIRSourceCol(LoopCount)).Copy
Results.Cells(DestinationRow, (LoopCount + 4)).PasteSpecia
(xlPasteValues)
Application.CutCopyMode = False
Next LoopCount
Results.Cells(DestinationRow, 7).Value = MatchType
Results.Cells(DestinationRow, 8).Value = CUCMSourceRow
Results.Cells(DestinationRow, 9).Value = ALIRSourceRow
Select Case MatchType
Case 0
Case 1
For LoopCount = 1 To 7
Results.Cells(DestinationRow, LoopCount).Interior.ColorIndex
GREEN
Next LoopCount
Case 2
For LoopCount = 1 To 7
Results.Cells(DestinationRow, LoopCount).Interior.ColorIndex =
YELLOW
Next LoopCount
Case 3
For LoopCount = 1 To 7
Results.Cells(DestinationRow, LoopCount).Interior.ColorIndex =
ORANGE
Next LoopCount
Case 4
For LoopCount = 1 To 7
Results.Cells(DestinationRow, LoopCount).Interior.ColorIndex = BLUE
Next LoopCount
End Select
End Function
I cannot see why I am getting this error can anyone please help me?
this line of code
If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) And UCase(CUCM.Cells(CUCMSourceRow, 2)
= UCase(ALIR.Cells(MainLoop, 14)) And (UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 12))) Then
the entire code this is from is
Sub Button1_Click()
Dim LastRow As Long
Dim LastResultRow As Long
Dim DestinationRow As Long
Dim ALIRSourceRow As Long
Dim CUCMSourceRow As Long
Dim MainLoop As Long
LastRow = ALIR.UsedRange.Rows.Count
DestinationRow = 3
ALIRSourceRow = 2
CUCMSourceRow = 2
MatchType = 0
LastResultRow = Results.UsedRange.Rows.Count
Results.Range(Cells(3, 1), Cells(LastRow, 9)).ClearContents
Results.Range(Cells(3, 1), Cells(LastRow, 9)).Interior.ColorIndex = 0
Do While CUCM.Cells(CUCMSourceRow, 3) <> ""
For MainLoop = 2 To LastRow
'If match all then MatchType = 1
If CUCM.Cells(CUCMSourceRow, 5) = Right(ALIR.Cells(MainLoop
32), 10) Then
MatchType = 3
ALIRSourceRow = MainLoop
'If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) Then
'If UCase(CUCM.Cells(CUCMSourceRow, 2))
UCase(ALIR.Cells(MainLoop, 14)) Then
'If UCase(CUCM.Cells(CUCMSourceRow, 1))
UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow, 1))
UCase(ALIR.Cells(MainLoop, 12)) Then
If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) And UCase(CUCM.Cells(CUCMSourceRow, 2)
= UCase(ALIR.Cells(MainLoop, 14)) And (UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 12))) Then
MatchType = 1
Call WriteRow(MainLoop, CUCMSourceRow, DestinationRow
MatchType)
DestinationRow = DestinationRow + 1
Exit For
Else
Call WriteRow(MainLoop, CUCMSourceRow, DestinationRow
MatchType)
DestinationRow = DestinationRow + 1
Exit For
End If
Else
'If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) Then
'If UCase(CUCM.Cells(CUCMSourceRow, 2))
UCase(ALIR.Cells(MainLoop, 14)) Then
'If UCase(CUCM.Cells(CUCMSourceRow, 1))
UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow, 1))
UCase(ALIR.Cells(MainLoop, 12)) Then
If UCase(CUCM.Cells(CUCMSourceRow, 4))
UCase(ALIR.Cells(MainLoop, 15)) And UCase(CUCM.Cells(CUCMSourceRow, 2)
= UCase(ALIR.Cells(MainLoop, 14)) And (UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 11)) Or UCase(CUCM.Cells(CUCMSourceRow
1)) = UCase(ALIR.Cells(MainLoop, 12))) Then
MatchType = 2
Call WriteRow(MainLoop, CUCMSourceRow, DestinationRow
MatchType)
DestinationRow = DestinationRow + 1
Exit For
End If
End If
Next MainLoop
CUCMSourceRow = CUCMSourceRow + 1
MatchType = 5
Loop
End Sub
Function WriteRow(ByVal ALIRSourceRow As Long, _
ByVal CUCMSourceRow As Long, _
ByVal DestinationRow As Long, _
ByVal MatchType As Integer)
Dim ALIRSourceCol(1 To 2) As Integer
Dim CUCMSourceCol(1 To 5) As Integer
Dim LoopCount As Integer
Dim GREEN As Integer
Dim YELLOW As Integer
Dim ORANGE As Integer
Dim BLUE As Integer
ALIRSourceCol(1) = 21 'Principal Country Location
ALIRSourceCol(2) = 28 'Unique Key
CUCMSourceCol(1) = 1 'First Name
CUCMSourceCol(2) = 2 'Last Name
CUCMSourceCol(3) = 3 'User ID
CUCMSourceCol(4) = 4 'Department
GREEN = 43
YELLOW = 6
ORANGE = 45
BLUE = 23
For LoopCount = 1 To 4
CUCM.Cells(CUCMSourceRow, CUCMSourceCol(LoopCount)).Copy
Results.Cells(DestinationRow, LoopCount).PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Next LoopCount
For LoopCount = 1 To 2
ALIR.Cells(ALIRSourceRow, ALIRSourceCol(LoopCount)).Copy
Results.Cells(DestinationRow, (LoopCount + 4)).PasteSpecia
(xlPasteValues)
Application.CutCopyMode = False
Next LoopCount
Results.Cells(DestinationRow, 7).Value = MatchType
Results.Cells(DestinationRow, 8).Value = CUCMSourceRow
Results.Cells(DestinationRow, 9).Value = ALIRSourceRow
Select Case MatchType
Case 0
Case 1
For LoopCount = 1 To 7
Results.Cells(DestinationRow, LoopCount).Interior.ColorIndex
GREEN
Next LoopCount
Case 2
For LoopCount = 1 To 7
Results.Cells(DestinationRow, LoopCount).Interior.ColorIndex =
YELLOW
Next LoopCount
Case 3
For LoopCount = 1 To 7
Results.Cells(DestinationRow, LoopCount).Interior.ColorIndex =
ORANGE
Next LoopCount
Case 4
For LoopCount = 1 To 7
Results.Cells(DestinationRow, LoopCount).Interior.ColorIndex = BLUE
Next LoopCount
End Select
End Function
I cannot see why I am getting this error can anyone please help me?