Hi,
I am using the below below to check with dynamic workbook & worksheet !!!!
Private Sub CommandButton5_Click()
Dim fileToOpen As String, fullRangeString As String, mVal As Variant
Dim wb As Workbook, c As Integer, cell As Integer
Dim Nwb As Workbook, Nws As Worksheet, rng As Range
Dim i As Long, lrng As Range, Col As Variant, look As Variant, lookfor As Variant
cell = WorksheetFunction.CountIfs(Sheet5.Range("A:A"), "<>")
Set wb = ThisWorkbook
fileToOpen = Application.GetOpenFilename
If fileToOpen = "False" Then Exit Sub
If IsOpen(fileToOpen) = False Then
'Workbooks.Open (fileToOpen)
Set Nwb = Application.Workbooks.Open(fileToOpen)
Else
Windows(fileToOpen).Activate
End If
Set rng = Application.InputBox( _
Prompt:="Select a cell for the output.", Title:="Select a column", _
Default:=ActiveCell.Address, Type:=8)
Col = rng.Columns.Count
Application.ScreenUpdating = False
Application.EnableEvents = False
Columns("G:G").ClearContents
Columns("G:G").NumberFormat = "@"
For i = 2 To cell
Set lrng = Sheet5.Cells(i, 1)
If Application.WorksheetFunction.IsText(lrng.Value) = True Then
mVal = Val(lrng.Value)
Else
mVal = lrng.Value
End If
look = Application.VLookup(mVal, rng, Col, 0)
If IsError(look) Then
lrng.Offset(0, 6).Value = ""
Else
lrng.Offset(0, 6).Value = look
End If
Next i
Nwb.Close False
Application.EnableEvents = True
Application.ScreenUpdating = True
c = WorksheetFunction.CountIfs(Sheet5.Range("G:G"), ">*")
If c <> 0 Then
Cells(1, 7).Value = "Matched"
Columns(7).Font.Bold = True
MsgBox c & " MSISDNs Found !!"
Else
MsgBox "No MSISDN matched !!!"
End If
'Application.EnableEvents = True
'Application.ScreenUpdating = True
End Sub