简体   繁体   English

Vlookup根据帐户值从另一个工作表获取数据

[英]Vlook up get data from another sheet based on account value

I am trying to create a macro for sending emails from outlook. 我正在尝试创建一个宏,用于从Outlook发送电子邮件。 I have few edits to be done with the raw data for that i have given codes. 对于给定代码的原始数据,我要进行的编辑很少。

Since im new to VBA i do not know how to use the Vlookup function and also im not very well versed in using vlookup in excel too :( I am trying to get the data from Master data(Sheet name)-Col A has Account & Col B has values. I want code to get the values of Col B if Col A in there in the Email output sheet. 由于我是VBA的新手,所以我不知道如何使用Vlookup函数,而且我也不是很精通在excel中使用vlookup :(我正在尝试从主数据(工作表名称)中获取数据-科尔A拥有帐户& Col B有值,如果电子邮件输出表中的Col A在其中,我希望代码获取Col B的值。

Master Data sample 主数据样本

Account Value
803     A
691     B
8010    C

I want to copy the values in the col I of the Email output sheet if the account number matches in the Col A.Can you help? 如果帐号与列A中的值匹配,我想复制电子邮件输出表的列I中的值。能帮上忙吗?

Col A Col I 上校

Account Value
803     Copy values from Master data depending on Account Value
691     Copy values from Master data depending on Account Value
8010    Copy values from Master data depending on Account Value

Here is my code, Im trying not use default VLOOKUP Function on vba, but use a logic behind that function to know how VLOOKUP works 这是我的代码,我试图不使用vb​​a上的默认VLOOKUP函数,而是使用该函数背后的逻辑来了解VLOOKUP的工作方式

With Sheets("Master Data")
    i1 = 2
    Do While Sheets("Email Output").Cells(i1, 1).Value <> vbNullString
        i2 = 2
        Do While .Cells(i2, 1).Value <> vbNullString
            If Sheets("Email Output").Cells(i1, 1).Value = .Cells(i2, 1).Value Then
                Sheets("Email Output").Cells(i1, 2).Value = .Cells(i2, 2).Value
                Exit Do
            End If
            i2 = i2 + 1
        Loop
        i1 = i1 + 1
    Loop
End With

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM