vba vlookup不生产正确的材料
我正在使用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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论