Krishna2385
New Member
I know this might be a silly issue but I tried all things which I learned from here.
I am receiving a Application defined error, and the Vlookup formula was working in my previous macros however this time it is a frustrating issue.
well I am trying to do a vlookup between two different workbooks and this is the code ( Please note I haven't completed the entire code I have a habit of executing and verifying if the code is working fine or ot and this is where I am receiving the error).
I am receiving a Application defined error, and the Vlookup formula was working in my previous macros however this time it is a frustrating issue.
well I am trying to do a vlookup between two different workbooks and this is the code ( Please note I haven't completed the entire code I have a habit of executing and verifying if the code is working fine or ot and this is where I am receiving the error).
Code:
Sub macro()
Dim Workingfile As Workbook
Dim PDMT As Workbook
Dim PSdata As Workbook
Dim Commodityfile As Workbook
Dim Segmentfile As Workbook
Dim Lrow As Integer
'Dim rng As String
'Dim Filepath As String
'Dim Filepos As String
Set Workingfile = Application.ActiveWorkbook
'Peoplesoft data
MsgBox ("Choose PSdata")
Filepath = Application.GetOpenFilename
Filepos = InStrRev(Filepath, "\")
Filenm = Right(Filepath, Len(Filepath) - Filepos)
Workbooks.Open Filename:=Filepath
Set PSdata = Workbooks(Filenm)
PSdata.Activate
LastRw = Range("A4").End(xlDown).Row
Range("A4", "L" & LastRw).SpecialCells(xlCellTypeVisible).Copy
Workingfile.Activate
Sheets("sheet1").Activate
Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
Columns("D:D").Insert Shift:=xlToRight
Columns("E:E").Insert Shift:=xlToRight
Columns("K:K").Insert Shift:=xlToRight
Columns("L:L").Insert Shift:=xlToRight
Columns("P: P").Insert Shift:=xlToRight
'commodity descp & tower lookup
MsgBox ("Choose Commodityfile")
Filepath = Application.GetOpenFilename
Filepos = InStrRev(Filepath, "\")
Filenm1 = Right(Filepath, Len(Filepath) - Filepos)
Workbooks.Open Filename:=Filepath
Set Commodityfile = Workbooks(Filenm1)
Workingfile.Activate
Sheets("sheet1").Activate
Range("D5:D" & Lrow).Formula = "=VLOOKUP(C5,'[" & Filenm1 & "]Sheet1'!$A:$C,3,0)"
End Sub
Last edited by a moderator: