简体   繁体   English

从Excel中的另一个单元格中找到一个单元格的单元格引用

[英]find cell reference of a cell from another cell in excel

I have a worksheet that returns a value from a different sheet in the sameworkbook (=data!C68) which returns a value. 我有一个工作表,它从同一工作簿(= data!C68)中的另一个工作表返回一个值,该工作表返回一个值。

Ina another cell I want to reference the reference in the original cell but increment the row by 1 - (=data!C69). 在另一个单元格中,我想引用原始单元格中的引用,但将行增加1-(= data!C69)。 The cells are not next to each other. 单元不彼此相邻。

Is this possible either with a function or a fromula? 通过功能或小舌可以做到吗?

Thanks 谢谢

Jonathan 乔纳森

There are many ways to achieve this. 有很多方法可以实现这一目标。 Here is one way. 这是一种方法。 I have extended the function by incorporating the rows and columns that you want to Offset. 我通过合并要偏移的行和列来扩展了功能。 Paste this code in a module 将此代码粘贴到模块中

Syntax 句法

=GetOffset(Range,Row,Col) = GetOffset(范围,行,颜色)

Remarks 备注

Range (Required) is the cell which has the formula 范围 (必填)是具有公式的单元格

Row (Optional) Row(s) you want to offset (可选)要偏移的行

Col (Optional) Column(s) you want to offset 上校 (可选)列(S)要偏移

Sample Usage 样品用量

=GetOffset(A1) : This will pickup the value from the same cell which A1 is referring to. = GetOffset(A1):这将从A1所引用的同一单元格中获取值。 If A1 is referring to =data!C69 then GetOffset will get value from data!C69 如果A1引用=data!C69GetOffset将从data!C69获取值。

=GetOffset(A1,1) : This will pickup the value from the next cell (1 row down) which A1 is referring to. = GetOffset(A1,1):这将从A1所引用的下一个单元格(向下1行)中提取值。 If A1 is referring to =data!C69 then GetOffset will get value from data!C70 如果A1引用=data!C69GetOffset将从data!C70获取值。

=GetOffset(A1,1,1) : This will pickup the value from the next cell (1 row down across 1 Col) which A1 is referring to. = GetOffset(A1,1,1):这将从A1所引用的下一个单元格(1行向下1行)中提取值。 If A1 is referring to =data!C69 then GetOffset will get value from data!D70 如果A1引用=data!C69GetOffset将从data!D70获取值。

=GetOffset(A1,0,1) : This will pickup the value from the next cell (Same row across 1 Col) which A1 is referring to. = GetOffset(A1,0,1):这将从A1所引用的下一个单元格(跨过1 Col的同一行)中获取值。 If A1 is referring to =data!C69 then GetOffset will get value from data!D69 如果A1引用=data!C69GetOffset将从data!D69获取值。

CODE

Public Function GetOffset(Rng As Range, Rw As Long, Col As Long) As Variant
    Dim MyArray() As String, strTemp As String
    Dim TempRow As Long, TempCol As Long

    On Error GoTo Whoa

    Application.Volatile

    MyArray = Split(Rng.Formula, "!")

    TempRow = Range(MyArray(UBound(MyArray))).Row
    TempCol = Range(MyArray(UBound(MyArray))).Column

    TempRow = TempRow + Rw
    TempCol = TempCol + Col

    strTemp = MyArray(0) & "!" & Cells(TempRow, TempCol).Address

    GetOffset = Application.Evaluate(Trim(strTemp))
    Exit Function
Whoa:
End Function
Option Explicit
Function GetCellReferenceUsedInFormula(ByVal src As Range) As Range
If src.HasFormula Then
    Set GetCellReferenceUsedInFormula = Evaluate(Mid(src.Formula, 2))
End If
End Function

And use the above function in formula with OFFSET 并在带有OFFSET公式中使用以上函数

=OFFSET(GetCellReferenceUsedInFormula(A1),1,0)

This is assuming that cell A1 contains the formula =data!C68 . 假设单元格A1包含公式=data!C68
Please note that the VBA code assumes that the formula is simple (ie =somecellreference ). 请注意,VBA代码假定公式很简单(即=somecellreference )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 excel 中添加来自另一个单元格的单元格引用 - How to add a cell reference from another cell in excel 参考另一个单元格的Excel单元格的输出 - Output for an Excel Cell with Reference to another Cell Powershell查找Excel单元格参考 - Powershell find excel cell reference 引用另一个单元格(VBA)的单元格值 - Reference a Cell value from another Cell (VBA) Excel,要根据其值查找一个单元格,然后从先前找到的单元格位置开始查找另一个单元格 - Excel, To find a cell based on its value then find another cell starting the search from the previously found cell position 从 Excel 中的另一个单元格控制单元格值 - Control cell value from another cell in Excel Excel宏查找文本,查找引用单元格,从引用单元格复制固定位置的数据 - Excel macro to find text, find a reference cell, copy data in a fixed position from the reference cell 来自单元的 excel 中的动态参考 - Dynamic reference in excel from cell EXCEL-如何查找具有特定内容的单元格,然后在另一个公式中引用该CELL(而不是其内容)? (内例) - EXCEL - How do I find a cell with specific content, and then reference that CELL (not its content) in another formula? (example within) 引用另一个工作表中的单元格 - Reference a cell from another worksheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM