Code:
Dim ws As Worksheet
Dim vFilePath As String
Dim CurrentFile As String
Dim Cellname As String
Dim vTable As String
Dim OutApp As Object
Dim OutMail As Object
Dim OutNS As Object
Dim EmailTo As String
Dim EmailCC As String
Dim EmailSub As String
Dim EmailBody As String
vFilePath = Range("rFilePath").Value
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Master" And ws.Name <> "Check" And ws.Name <> "Data" And ws.Name <> "Template" _
And ws.Name <> "Library" And ws.Name <> "Total EQL Scorecard" And ws.Name <> "EQL Com Scorecard" _
And ws.Name <> "Control" Then
Cellname = ws.Range("A7")
CurrentFile = vFilePath & Cellname & ".xlsx"
ws.Copy
ThisWorkbook.Sheets("Master").Copy after:=ActiveSheet
ActiveWorkbook.SaveAs Filename:=CurrentFile, _
FileFormat:=xlOpenXMLWorkbook
EmailTo = Application.WorksheetFunction.VLookup(Cellname, _
ThisWorkbook.Sheets("Library").Range("vTable"), 6, 0)
I searched in the forum for similar cases and I believe I have all the issues that were brought up correct; variables defined, quotes where they are suppose to be.. But my vlookup is not returning the correct value.
cellname is located on the workbook that was created
vtable is located on the original workbook and the first column has the names that it is looking up and it is suppose to retrieve an email address in the last column.
6 is the correct number because i tried it using a formula on the worksheet.
When I ran the macro only two workbooks (should be 8) that were created were sent in an email and they were sent to the wrong email.
Am I missing something when I defined the variables?
Thanks for any and all help