I have a workbook with 2 worksheets. If a user clicks within a particular column, the second worksheet is activated and the data is filtered based on the value of the cell in worksheet 1. I use the function InRange (see code) to see if the user has clicked in the designated column in order to activate the code.
I also have another column where the user can click a hyperlink. When this is done, a specific workbook is opened based on values on that row.
The problem I am having is that when the user clicks on the hyperlink the first time, the code fails with an error:
Run time error '1004'
Method 'Intersect' of object '_Application' failed.
The second time the user clicks on the same hyperlink, the code works.
The hyperlink formula on the spreadsheet is:
=IF(J22="","",HYPERLINK(K22,"Workbook"))
Thanks.
I also have another column where the user can click a hyperlink. When this is done, a specific workbook is opened based on values on that row.
The problem I am having is that when the user clicks on the hyperlink the first time, the code fails with an error:
Run time error '1004'
Method 'Intersect' of object '_Application' failed.
The second time the user clicks on the same hyperlink, the code works.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim sStatementID As String
If InRange(ActiveCell, Range("LinkColumn")) Then
sStatementID = ActiveCell.Value
Call FilterTo1Criteria(sStatementID)
Else
End If
End Sub
Sub FilterTo1Criteria(sStatementID)
Application.Sheets("Summary").Activate
With Sheet2
.AutoFilterMode = False
.Range("A6:e6").AutoFilter
.Range("A6:e6").AutoFilter Field:=4, Criteria1:=sStatementID
End With
End Sub
Function InRange(Range1 As Range, Range2 As Range) As Boolean
' returns True if Range1 is within Range2
Dim InterSectRange As Range
Set InterSectRange = Application.Intersect(Range1, Range2)
InRange = Not InterSectRange Is Nothing
Set InterSectRange = Nothing
End Function
The hyperlink formula on the spreadsheet is:
=IF(J22="","",HYPERLINK(K22,"Workbook"))
Thanks.