swathidas,
Give the following a try:
Sub tgr()
Const strFldrPath As String = "C:\DataFiles\"
Application.ScreenUpdating = False
Dim CurrentFile As String: CurrentFile = Dir(strFldrPath & "*.xls*")
Dim wb As Workbook
Dim ws As Worksheet
Dim Col As String
While CurrentFile <> vbNullString
Set wb = Workbooks.Open(strFldrPath & CurrentFile)
For Each ws In wb.Sheets
If ws.Name = "Dev" Or ws.Name = "Test" Then
Select Case ws.Name
Case "Dev": Col = "F"
Case "Test": Col = "N"
End Select
Intersect(ws.UsedRange.Offset(1).Resize(ws.UsedRange.Rows.Count - 1), ws.Columns(Col)).Value = wb.Name
End If
Next ws
wb.Close False
CurrentFile = Dir
Wend
Application.ScreenUpdating = True
End Sub
Bookmarks