为什么我的Vlookup VBA代码显示400的错误
我在同一工作簿和单独的工作表中具有相同的代码,并且它工作得很好。我为同一工作簿但不同的工作表复制了相同的代码,但出现错误。
Sub ExecuteLkup()
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Dim wb As Workbook
Set wb = Workbooks.Open(Filename:="V:\Mar22\Top Segments & Top All_Mar22.xlsx")
Set ws = Sheet4
Range("K2").Value = WorksheetFunction.Vlookup(Range("F").Value, wb.Sheets("TopAll").Range("E:I"), 5, 0)
With ws
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Variance"
End With
Range("L2").Select
ActiveCell.FormulaR1C1 = "=[@[BRN_nett_grand_total]]-[@Column1]"
End Sub
I have the same code in the same workbook and in a separate sheet and it was working perfectly alright. I copied the same code for the same workbook but different sheet and there goes an error.
Sub ExecuteLkup()
Dim LastRow As Long
Dim LastCol As Long
Dim iRow As Long
Dim wb As Workbook
Set wb = Workbooks.Open(Filename:="V:\Mar22\Top Segments & Top All_Mar22.xlsx")
Set ws = Sheet4
Range("K2").Value = WorksheetFunction.Vlookup(Range("F").Value, wb.Sheets("TopAll").Range("E:I"), 5, 0)
With ws
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
.Cells(1, LastCol + 1).Value = "Variance"
End With
Range("L2").Select
ActiveCell.FormulaR1C1 = "=[@[BRN_nett_grand_total]]-[@Column1]"
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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