PDA

View Full Version : Debugging Runtime Error '13' Type Mismatch



jmeager
07-20-2011, 07:47 AM
Hi everyone,

I keep getting a run-time error '13' type mismatch for the below code. Could anybody help? It's on the line Set pathFound = Cells(1, pathCol).EntireColumn.Find(customerPath)



Private Sub buttonReport_Click()

Dim ws As Worksheet
Set ws = Worksheets("Sheet1") ' data

Const pathCol As Integer = 4 ' column for paths
Const countCol As Integer = 5 ' column for path counts

Dim reportRow As Long

Dim customerPath As String
Dim conversionID As String
Dim campaign As String

Dim pathFound As Range

Dim c As Range ' to iterate through campaigns
Set c = ws.[A2]

Cells.Clear
Cells(1, pathCol) = "Path"
Cells(1, countCol) = "Count"

reportRow = 1

Do While c <> ""

campaign = c.Value
conversionID = c.Offset(0, 1).Value
customerPath = ""
' Build path for this conversion
Do While c.Offset(0, 1).Value = conversionID
customerPath = customerPath & c.Value & ", "
Set c = c.Offset(1, 0)
Loop
' removed trailing comma
customerPath = Mid(customerPath, 1, Len(customerPath) - 2)

' Does this path exist?
Set pathFound = Cells(1, pathCol).EntireColumn.Find(customerPath)
If pathFound Is Nothing Then
' Add new path to report
reportRow = reportRow + 1
Cells(reportRow, pathCol) = customerPath
Cells(reportRow, countCol) = 1
'Cells(reportRow, countCol + 1) = conversionID ' list conversion IDs for debugging
Else
' Increment count for this path
pathFound.Offset(0, 1) = pathFound.Offset(0, 1) + 1
'Cells(reportRow, countCol + 1) = Cells(reportRow, countCol + 1) & ", " & conversionID ' list conversion IDs for debugging
End If

Loop

' Format report
Cells(1, pathCol).Font.Bold = True
Cells(1, countCol).Font.Bold = True

Cells(1, pathCol).AutoFilter
AutoFilter.Sort.SortFields.Clear
AutoFilter.Sort.SortFields.Add _
Key:=Cells(1, countCol).EntireColumn, _
SortOn:=xlSortOnValues, _
Order:=xlDescending, _
DataOption:=xlSortNormal
With AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With


End Sub

Bob Phillips
07-20-2011, 09:44 AM
Does that value exist? Try wrapping error handling around it.