Vlookup in different workbooks, used for email address

ss6857

New Member
Joined
Jan 17, 2011
Messages
27
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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
cellname is located on the workbook that was created
... it looks like it's located in the workbook where the code is located.
 
Upvote 0
You'd have to tell me what you are trying to do .... where is the cell that you want to use in the lookup?
 
Upvote 0
I figure it out. It still works because it identifies the cell value before I cut and paste the sheet to another workbook. It works good. Thank you for your input though. I appreciate the reply.
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,304
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top