原文:http://spreadsheetpage.com/index.php/tip/a_custom_function_for_relative_sheet_references/
批注:经过多个实现版本的比较,认为这个版本兼容性比较好。
我们经常需要引用别的sheet的内容。但是EXCEL只提供基于sheet页名字的访问,并没有提供第几页查询的功能。
Function SHEETOFFSET(offset, Ref)
' Returns cell contents at Ref, in sheet offset
Application.Volatile
With Application.Caller.Parent
SHEETOFFSET = .Parent.Sheets(.Index + offset) _
.Range(Ref.Address).Value
End With
End Function
Function sheetat(offset, Ref)
' Returns cell contents at Ref, in sheet offset
Application.Volatile
With Application.Caller.Parent
sheetat = .Parent.Sheets(offset) _
.Range(Ref.Address).Value
End With
End Function
' Returns cell contents at Ref, in sheet offset
Application.Volatile
With Application.Caller.Parent
sheetat = .Parent.Sheets(offset) _
.Range(Ref.Address).Value
End With
End Function
例如:
1、前一页的A1值: =SHEETOFFSET(-1,A1)
2、后一页的B1值:=SHEETOFFSET(1,B1)
3、第一页的C3值:=SHEETAT(1,C3)
注意:当引用到图表的时候,会发生错误。最后,感谢那些为办公软件做出贡献的人。