English 中文(简体)
简单参考单元格
原标题:Easily reference cells in offset

我有一个包含许多公式的工作表, 上面或右边有一个单元格。 如果我使用 ctrl- D 来弹射行, 公式会得到正确更新( 因此, B2 中的 =B1 + A2 改为 B2 = B2+ A3 改为 B3 ), 但是当我在行间插入时, 情况就会混乱( 所以在 B3 上插入一行, 移动到 B4 使公式变成 = B2+A4, 这并不是我想要的) 。

所以我想建立一个细胞机器人和细胞权利配方(这样我才能写出 = CellAbove () + CellAbove () + CellRight ())。 我该怎么做呢?

我的尝试:

Function CellAbove()
   CellAbove = [Address(Row() - 1, Column())].Value
End Function

不工作。

UPDATE: The function below works, but cells that have it are not updated:

Function CellAbove()
   CellAbove = Range([Address(Row() - 1, Column())])
End Function

所以如果A1有2和A2有=CellAbove () 那么A2会显示2 但如果我现在把A1换为3 那么A2仍然会显示2

最佳回答

Since your function worked, and it seemed all you needed was it to recalculate when you insert rows. you said:

“但有不更新的单元格”

User Defined Functions are by default NOT volatile so they won t automatically recalculate. You could change your existing function to this.

Function CellAbove()
 Application.Volatile (True)
 CellAbove = Range([Address(Row() - 1, Column())])
End Function

这可能影响业绩,但似乎是你所要求的。

问题回答

=INDirect (“R” & amp;ROW ()-1 & amp; “C” & amp; COLUMN (), FALSE) 将作为一个函数发挥作用 。

假设您在 B2 上, 那么括号中的位数会评价为 R1C2 。 INIDRECT 函数将计算行 1 列 2 的值( 您需要 FALSE 以确保您使用单元格地址的 R1C1 样式 ) 。

我相信你可以做一些更简单的事情 使用:

FOFSET(现价,-1,0)

但我看不清你如何引用当前单元格。

我们不需要Vba来做这个:)

在插入空行之后

< 强 > 步骤1 < /强 >

将公式从 B2 拖到 B3 或简单选择 B3 并按 CTL D

<强 > 步骤2

选择单元格 B3 。 在单元格右下角双击自动填充 。

""https://i.sstatic.net/jgmRZ.png" alt="此处输入图像描述"/ >

你可以使用内置的Excel函数来做到这一点,如Indirect、ADSESS、ROW和COLUMN,例如...

=INDIRECT(ADDRESS(ROW()-1,COLUMN()))

...上面的细胞,或者...

=INDIRECT(ADDRESS(ROW(),COLUMN()+1))

...细胞向右转

另一个方法,再次使用内置能力,就是使用OFFSET 函数。例如,在单元格B2中,您可以输入公式...

=OFFSET(B2,-1,0)

...上面的细胞,或者...

=OFFSET(B2,0,1)

...细胞向右转 It looks like a circular reference, but it s not, since you are not referencing the value of the same cell, only its address.

无论哪种方式,你或多或少失去了使用“追踪依赖者”和“追踪先例”功能的能力,因为每个单元格基本上只提到本身。

您的“ / 强/ 强/ 强/ 强/ 强” 功能

Function CellAbove()
   CellAbove = Range([Address(Row() - 1, Column())])
End Function

Function CellRight()
   CellRight = Range([Address(Row(), Column() + 1)])
End Function

可能被称为

Function test000000()
    ActiveCell = CellAbove + CellRight
End Sub




相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签