Development Tip

'CELL TO THE LEFT'를 참조하는 Excel 수식

yourdevel 2020. 10. 28. 21:10
반응형

'CELL TO THE LEFT'를 참조하는 Excel 수식


값이 왼쪽 셀의 값과 다른 경우 셀 색상이 변경되도록 조건부 서식을 지정하려고합니다 (각 열은 한 달이고 각 행은 특정 개체에 대한 비용입니다. 모니터링하고 싶습니다. 수개월에 걸쳐 쉽게 가격이 변경됩니다.)

셀 단위로 할 수 있고 서식을 드래그하여 드래그 할 수 있지만 일반 수식을 전체 워크 시트에 적용하고 싶습니다.

감사!


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

가장 짧은 가장 호환되는 버전은 다음과 같습니다.

=INDIRECT("RC[-1]",0)

"RC [-1]"은 왼쪽에 한 열을 의미합니다. "R [1] C [-1]"은 왼쪽 하단입니다.

두 번째 매개 변수 0은 첫 번째 매개 변수가 R1C1 표기법을 사용하여 해석됨을 의미합니다.

다른 옵션 :

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

제 생각에는 너무 깁니다. 그러나 상대 값이 동적이거나 다른 셀에서 파생 된 경우 유용합니다. 예 :

=OFFSET(INDIRECT(ADDRESS(ROW(), COLUMN())),0, A1)

가장 간단한 옵션 :

= RC[-1]

옵션을 사용하여 R1C1 표기법을 켜야한다는 단점이 있습니다. 이는 다른 사람들이 엑셀을 사용해야 할 때 진행되지 않습니다.


조건부 서식을 만들 때 원하는 항목 (전체 시트)에 적용 할 범위를 설정 한 다음 왼쪽 상단 모서리 만 서식을 지정하는 것처럼 상대 수식 을 입력 ( $기호 제거)합니다 .

Excel은 그에 따라 나머지 셀에 서식을 올바르게 적용합니다.

이 예에서 B1부터 시작하여 왼쪽 셀은 A1이됩니다. 고급 공식이 필요하지 않습니다.


당신이 뭔가 더 고급을 찾고 있다면, 당신은 함께 놀러 수 column(), row()indirect(...).


R1C1 표기법 (도구 | 옵션, 일반 탭)을 사용하도록 셀 참조를 변경 한 경우 간단한 표기법을 사용하여 셀에 붙여 넣을 수 있습니다.

이제 공식은 간단합니다.

=RC[-1]

매우 긴 글을 쓰는 대신 :

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

다음과 같이 간단히 작성할 수 있습니다.

=OFFSET(*Name of your Cell*,0,-1)

따라서 예를 들어 Cell B2에 쓸 수 있습니다 .

=OFFSET(B2,0,-1)

B1 셀 참조

여전히 감사합니다 Jason Young !! 나는 당신의 대답 없이는이 해결책을 결코 생각해 내지 못했을 것입니다!


다음 공식으로 A1 셀을 채 웁니다 .

 =IF(COLUMN(A1)=1;"";OFFSET(A20;0;-1))&"1"

그런 다음 오른쪽으로 자동 확장하면

 1|  A  |  B  |  C  |  ect ect
 2|    1|   11|  111|  ect ect

오프셋이 사용 가능한 셀 범위를 벗어나면 #REF! 오류.

즐기시기 바랍니다.


더 간단합니다.

=indirect(address(row(), column() - 1))

OFFSET은 현재 참조에 상대적인 참조를 반환하므로 간접적으로 올바른 참조를 반환하는 경우 필요하지 않습니다.


사용자 정의 함수를 만들 때 기능 OFFSET관련된 다른 답변은 INDIRECT적용 할 수 없다는 것을 알았습니다 .

대신 Application.Caller사용자 정의 함수 (UDF)가 사용 된 셀을 참조하기 위해를 사용해야 합니다. 두 번째 단계에서 열의 인덱스를 해당 열의 이름으로 변환합니다.
마지막으로 활성 워크 시트의 범위 함수를 사용하여 왼쪽 셀을 참조 할 수 있습니다 .

Function my_user_defined_function(argument1, argument2)
    ' Way to convert a column number to its name copied from StackOverflow
    ' http://stackoverflow.com/a/10107264
    ' Answer by Siddarth Rout (http://stackoverflow.com/users/1140579/siddharth-rout)
    ' License (if applicable due to the small amount of code): CC BY-SA 3.0
    colName = Split(Cells(, (Application.Caller(1).Column - 1)).Address, "$")(1)

    rowNumber = Application.Caller(1).Row

    left_cell_value = ActiveSheet.Range(colName & rowNumber).Value

    ' Now do something with left_cell_value

선택 항목의 조건부 서식을 변경하는 VBA 스크립트를 사용할 수 있습니다 (조건 및 서식을 적절하게 조정해야 할 수 있음).

For Each i In Selection
i.FormatConditions.Delete
i.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:="=" & i.Offset(0, -1).Address
With i.FormatConditions(1).Font
    .Bold = True
End With
Next i

I stumbled upon this thread because I wanted to always reference the "cell to the left" but CRUCIALLY in a non-volatile way (no OFFSET, INDIRECT and similar disasters). Looking the web up and down, no answers. (This thread does not actually provide an answer either.) After some tinkering about I stumbled upon the most astonishing method, which I like to share with this community:

Suppose a starting value of 100 in E6. Suppose I enter a delta to this value in F5, say 5. We would then calculate the continuation value (105) in F6 = E6+F5. If you want to add another step, easy: just copy column F to column G and enter a new delta in G5.

This is what we do, periodically. Each column has a date and these dates MUST BE in chronological order (to help with MATCH etc). Every so often it happens that we forget to enter a step. Now suppose you want to insert a column between F and G (to catch up with your omission) and copy F into the new G (to repopulate the continuation formula). This is NOTHING SHORT of a total disaster. Try it - H6 will now say =F6+H5 and NOT (as we absolutely need it to) =G6+H5. (The new G6 will be correct.)

To make this work, we can obfuscate this banal calculation in the most astonishing manner F6=index($E6:F6;1;columns($E1:F1)-1)+F5. Copy right and you get G6=index($E6:G6;1;columns($E1:G1)-1)+G5.

This should never work, right? Circular reference, clearly! Try it out and be amazed. Excel seems to realize that although the INDEX range spans the cell we are recalculating, that cell itself is not addressed by the INDEX and thus DOES NOT create a circular reference.

So now I am home and dry. Insert a column between F and G and we get exactly what we need: The continuation value in the old H will refer back to the continuation value we inserted in the new G.


Why not just use:

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

Make a named formula "LeftCell"

For those looking for a non-volatile answer, you can accomplish this by using the INDEX function in a named formula.

  1. Select Cell A2
  2. Open Name Manager (Ctrl+F3)
  3. Click New
  4. Name it 'LeftCell' (or whatever you prefer)
  5. For Scope:, select Workbook
  6. In Refers to:, enter the formula:

    =INDEX(!A1:!A2, 1)

  7. Click OK and close Name Manager

This tells Excel to always look at the value immediately to the left of the current cell, and will change dynamically as different cells are selected. If the name is used alone it provides the cell's value, but in a range it uses the reference. Credit to this answer about cell references for the idea.


I think this is the easiest answer.

Use a "Name" to reference the offset.

Say you want to sum a column (Column A) all the way to, but not including, the cell holding the summation (say Cell A100); do this:

(I assume you are using A1 referencing when creating the Name; R1C1 can subsequently be switched to)

  1. Click anywhere in the sheet not on the top row - say Cell D9
  2. Define a Named Range called, say "OneCellAbove", but overwrite the 'RefersTo' box with "=D8" (no quotes)
  3. Now, in Cell A100 you can use the formula
    =SUM(A1:OneCellAbove)

Please select the entire sheet and HOME > Styles - Conditional Formatting, New Rule..., Use a formula to determine which cells to format and Format values where this formula is true::

=A1<>XFD1

Format..., select choice of formatting, OK, OK.

참고URL : https://stackoverflow.com/questions/507253/excel-formula-to-reference-cell-to-the-left

반응형