打开文件上的VBA Vlookup

时间:2015-09-16 04:51:32

标签: vba excel-vba vlookup excel

关于VLOOKUP,我需要一些关于VBA的帮助。错误弹出说“应用程序定义或对象定义错误。有时它显示”对象需要“。提前谢谢。我记录了宏但是当我把它放在VBA上时它不起作用

  Sub CopyData()
  '
  Dim Newbook As Window
  Dim wb As Workbook, wb2 As Workbook
  Dim ws As Worksheet
  Dim vFile As Variant

  Set wb = ActiveWorkbook

  For Each wkb In Workbooks ' Looking for new file created on multiple workbooks
  If Left(wkb.Name, 4) = "Book" Then
  Set wb3 = wkb
  Exit For
  End If
  Next wkb
  wkb.Activate          
  Sheets("Prices").Select' Selecting the sheet of the newly created workbook
  Range("F2").Select
  vFile = Application.GetOpenFilename("All-Files,*.xl**", 1, "Select One File To Open", , False) 'Open the data source workbook
  If TypeName(vFile) = "Boolean" Then Exit Sub
  Workbooks.Open vFile
  Range("F2").Text = "=VLOOKUP(RC[-4]&MID(RC[-3],3,3),[" & vFile & "]Sheet1!R3C1:R8149C15,15,FALSE)"
  Range("F2").Select
  Selection.AutoFill Destination:=Range("F2:F" & Cells(Rows.Count, 1).End(xlUp).Row)
  End Sub

0 个答案:

没有答案