是否有可能在Excel中(任何版本)从不同的工作表中创build自动完成?

我search了一切可能的东西,滚动到类似的主题,但没有find直接的答案/解决scheme。

我有工作表A和B.

在表A上,我input了一个客户的名字,并且需要它从位于表B的列表中自动完成。

input完客户名称后,我需要将与该客户相关的所有相关信息(地址,电话号码,传真号码)插入到表单B中的同一个表单中。

这可能在Excel中吗?

在sheetA的内部代码中,你把这个…

 Private Sub Worksheet_Change(ByVal Target As Range) 'You want to insert the data in column B Dim i Dim r r = Target.Row i = Target.Column If i = 2 Then 'you want to to put the telephone in column C Range(Cells(r, i + 1), Cells(r, i + 1)).Value = Application.WorksheetFunction.VLookup(Target.Value, Range([...]), [integer], False|True) 'you want to to put the address in column d Range(Cells(r, i + 2), Cells(r, i + 2)).Value = Application.WorksheetFunction.VLookup(Target.Value, Range([...]), [integer], False|True) End If End Sub 

或者可能是你想看看单元格内的公式

 Private Sub Worksheet_Change(ByVal Target As Range) 'You want to insert the data in column B Dim i Dim r r = Target.Row i = Target.Column If i = 2 Then 'you want to to put the telephone in column C Range(Cells(r, i + 1), Cells(r, i + 1)).FormulaR1C1 = "=VLOOKUP(RC[-1],SheetB!R1C6:R13C10,2,FALSE)" 'you want to to put the address in column d Range(Cells(r, i + 2), Cells(r, i + 2)).FormulaR1C1 = "=VLOOKUP(RC[-2],SheetB!R1C6:R13C10,3,FALSE)" End If End Sub 

通过这种方式,每次在某个列B中的任何单元格中插入一些数据,在同一行的列C中,就会得到与列B相同行中的列D中的数据。

编辑#1以防万一:在第一个例子中,实际代码中的Application.WorksheetFunction.VLookup(Target.Value, Range([...]), [integer], False|True)就像这样

 Application.WorksheetFunction.VLookup(Target.Value, Range("F1:J13"), 2, False) Application.WorksheetFunction.VLookup(Target.Value, Range(Cells(1,6),cells(13,10)), 2, False) 

这两条线是一样的。

编辑

更改Worksheet_ChangefunctionSelectionChange