Search code examples
excelcell

Excel setting an indirect cell value


I have three columns, A, B, C. In column C I have a variable value 1,2,3 etc., in column 2 I want to have an equation such that A gets set based on the value of C.

For example: if(c=1,cell(A)="illegal", if(c=2,cell(A)="legal",""))

Is this possible, how do I do it?

Note: this is a simple example of what I want to accomplish, Columns A-Z will be filled in with Text data from a third party, column C (AC in reality) is referenced from another spreadsheet. Basically filling in the blanks.

I know I could do this with a macro but I don't want to if I can get away with it.


Solution

  • Pertinent to your task description, you can enter the Worksheet formula in Cell A1

    =IF(C1=2,"legal",IF(C1=1,"illegal",""))
    

    and then expand it to the entire range in column A. The text in this column will correspond to values 1 or 2 in the Column C (as per your description). For any other value in Column C it will show blank ("").

    Though your task description isn't clear enough, but if by "indirect cell reference" you mean getting the text from cells in another worksheet (instead of hardcoding it) then you can follow the example shown below:

    =IF(C1=2,Sheet2!C1,IF(C1=1,Sheet2!C2,""))
    

    where the actual text is stored in Sheet2, cells C1 and C2, correspondingly. Also, you can apply the absolute reference (i.e., cell column/row prefixed by $ sign as shown below), depends on your business logic:

    =IF(C1=2,Sheet2!$C$1,IF(C1=1,Sheet2!$C$2,""))
    

    There are couple other Excel Worksheet Functions, which may be useful pertinent to your case: INDEX(Range, RowNum, ColumnNum) and INDIRECT(refText,boolVal); in the latter refText contains the reference to a Cell either in A1 style (if boolVal=TRUE, or just omitted), or R1C1 style (if boolVal=FALSE).

    Hope this will help. Regards,