I have a VBA macro that allows the user to search for a value across numerous workbooks. The results of the search is then displayed in a listbox within the macro search form. When clicking on a row within this listbox, the row on the related excel workbook should activate and display on the related cell. However I am getting a 1004 error on the range.activate (rngCell.Activate) code that activates the cell within the workbook. I have tested this code through the debugger and it doesn't crash, however it crashes when using it otherwise. Is there any solution I could use for this?
Private Sub lbxFinds_Change()
'Private Sub lbxFinds_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim wbName As String
Dim wsName As String
Dim cellAddress As String
Dim cellContent As String
Dim Wb As Workbook
Dim Ws As Worksheet
Dim rngCell As Range
With Me.lbxFinds
If .ListIndex < 0 Then Exit Sub
If .List(.ListIndex, 0) = "Text not found." Then Exit Sub
wbName = .List(.ListIndex, 0)
wsName = .List(.ListIndex, 1)
cellAddress = .List(.ListIndex, 2)
cellContent = .List(.ListIndex, 3)
End With
Set Wb = Workbooks(wbName)
Set Ws = Wb.Worksheets(wsName)
Set rngCell = Ws.Range(cellAddress)
Wb.Activate
Ws.Activate
rngCell.Activate
Me.lbxFinds.SetFocus
Set Wb = Nothing
Set Ws = Nothing
End Sub