原文: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)
注意:当引用到图表的时候,会发生错误。最后,感谢那些为办公软件做出贡献的人。
本文介绍了一种在Excel中使用VBA自定义函数实现相对工作表引用的方法,通过SHEETOFFSET和sheetat函数,可以方便地引用不同工作表中的单元格内容。
838

被折叠的 条评论
为什么被折叠?



