Linking to specific cells in pivot table
Guest
Runtime Error '13': Type mismatch
Hi - as I am developing a spreadsheet that I am working on, I am saving new
versions with every somewhat significant change I make to the spreadsheet.
For some reason, the ALMOST identical code works in one version of the
spreadsheet, but not in the other. In the scenario it is not working, I am
getting the error "Runtime Error '13': Type mismatch". Below is the code
for both scenarios:
- Scenario 1 (code works fine)
Sub test1()
Dim A
Dim B
Dim C
Dim testvalue
Dim range1 As range
Sheets("Frequency Input").Select
range("A1").Select
range(Selection, Selection.End(xlDown)).Select
range(Selection, Selection.End(xlToRight)).Select
Set range1 = Selection
range("L2").Select
Set testvalue = Selection
For Each A In range1
For Each B In range1
If B.Value <> A.Value Then
If Abs(A - B) <= testvalue Then
Sheets("Test Results").Select
range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.Value = "Interference"
ActiveCell.Offset(0, 1).Select
Selection.Value = A.Value
ActiveCell.Offset(0, 1).Select
Selection.Value = B.Value
End If
End If
Next
Next
End Sub
Scenario 2 (code not working - getting "Runtime Error '13': Type mismatch"
on the line 'If Abs(A - B) <= testvalue Then' below):
Sub test1()
Dim A
Dim B
Dim C
Dim testvalue
Dim range1 As range
Sheets("Frequency Input").Select
range("A6").Select
range(Selection, Selection.End(xlDown)).Select
range(Selection, Selection.End(xlToRight)).Select
Set range1 = Selection
range("L2").Select
Set testvalue = Selection
For Each A In range1
For Each B In range1
If B.Value <> A.Value Then
If Abs(A - B) <= testvalue Then
Sheets("Test Results").Select
range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select
Selection.Value = "Interference"
ActiveCell.Offset(0, 1).Select
Selection.Value = A.Value
ActiveCell.Offset(0, 1).Select
Selection.Value = B.Value
End If
End If
Next
Next
End Sub
Can anyone help me understand why in the world this is happening? It's
driving me crazy....Thanks in advance!
Bookmarks