Hello everyone, the following code is working fine for the first time when I run it and giving "Run-time error '13': Type mismatch" at line #15 during the second time and so on....
The code is working sometimes and sometimes not!
Please kindly let me know what to do?
Thanks in advance.
The code is working sometimes and sometimes not!
Please kindly let me know what to do?
Thanks in advance.
Code:
Sub RunMacro()
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.Worksheet
Dim LastUsedRow As Long
Set xlApp = New Excel.Application
With xlApp
.Visible = True
.Interactive = True
Set xlWB = .Workbooks.Open("C:\ExtractPolicyList.xls", , False)
Set xlWS = xlWB.Worksheets("SelectPolicies")
If .WorksheetFunction.CountA(xlWS.Cells) > 0 Then
LastUsedRow = xlWS.Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
MsgBox "" & LastUsedRow
End If
End With
End Sub
Comment