vba vlookup不生产正确的材料

发布于 2025-02-06 12:10:58 字数 740 浏览 1 评论 0原文

我正在使用VBA中的Vlookup来绘制我已合并的匹配数据。由于数字,我没有合并所有数据,现在正在尝试使用Vlookup从原始数据中获取一些数据。

我不确定我的Vlookup代码在哪里,因为对于多行,即使标准不同,它也会产生相同的输出。

这是我的代码:

Dim i As Integer 
N = 10000
Range("H2").Activate
myrange = Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, 
 ActiveCell.End(xlToRight).Column))
 Range("C2").Select
 For i = 2 To N
    userlogin = Range("C" & i)
    UserName = Application.WorksheetFunction.VLookup(userlogin, myrange, 1)
    UserID = Application.WorksheetFunction.VLookup(userlogin, myrange, 2)
    Range("A" & i) = UserName
    Range("B" & i) = UserID
   Next i

因此,基本上,我的数据看起来像附件的图像,但要排更多。 C列是我用作匹配条件的标准。最后,我希望列H和我成为列A和

B。 png“ rel =“ nofollow noreferrer”> mydataset

I am using vlookup in VBA to pull matching data that I have consolidated. Because of numbers, I didn't consolidate all the data and am now trying to pull some data from the original data by using vlookup.

I am not sure where my vlookup code is wrong, because for multiple rows it'll produce the same output even though the criteria is different.

This is my code:

Dim i As Integer 
N = 10000
Range("H2").Activate
myrange = Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, 
 ActiveCell.End(xlToRight).Column))
 Range("C2").Select
 For i = 2 To N
    userlogin = Range("C" & i)
    UserName = Application.WorksheetFunction.VLookup(userlogin, myrange, 1)
    UserID = Application.WorksheetFunction.VLookup(userlogin, myrange, 2)
    Range("A" & i) = UserName
    Range("B" & i) = UserID
   Next i

So basically, my data looks like the attached image but for a lot more rows. Column C is what I'm using as my criteria to match. In the end, I want columns H and I to be columns A and B. Right now, however, when I do it I get the same value for all

mydataset

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文