|
本帖最后由 zjdh 于 2017-5-8 17:09 编辑
不能!
改成就可以啦
Sub test()
Application.ShowWindowsInTaskbar = False
Dim rng As Range, sr As String, col%, row%, i%, n%, wb
Set sth = ActiveSheet
Set rng = Application.InputBox("请选择【选我测试】所在的单元格", "选择", Type:=8)
Application.ScreenUpdating = False
sr = rng.Value
col = rng.Column
row = rng.row
n = Cells(Rows.Count, col).End(xlUp).row
Set wb = Workbooks.Open("D:\数据\数据源.xlsx")
rng.Offset(0, 1).EntireColumn.Insert , copyorigin:=xlFormatFromLeftOrAbove
rng.Offset(0, 1) = "测试数据"
On Error Resume Next
For i = row + 1 To n
With sth
.Cells(i, col).Offset(0, 1) = Application.WorksheetFunction.VLookup(Right(.Cells(i, col), 4), wb.Sheets("x").Range("d:f"), 2, 0)
.Cells(i, col).Offset(0, 1) = Application.WorksheetFunction.VLookup(Right(.Cells(i, col), 4), wb.Sheets("y").Range("d:f"), 3, 0)
End With
Next i
wb.Close False
Set sth = Nothing
Set wb = Nothing
Application.ShowWindowsInTaskbar = True
Application.ScreenUpdating = True
End Sub
|
|