Friday, 31 January 2025

INDIRECT

 The INDIRECT function in Excel is a powerful tool that allows you to reference cells dynamically. It converts a text string into a cell reference, which can be particularly useful when you want to create flexible formulas or reference cells based on variable inputs. Below are 10 examples of how you can use the INDIRECT function, including both data and formulas.

Example 1: Basic INDIRECT Function

Data:

  • Cell A1: 10

  • Cell B1: A1

Formula:

excel
Copy
=INDIRECT(B1)

Result: 10
Explanation: The formula in B1 references A1, so INDIRECT(B1) returns the value in A1, which is 10.

Example 2: Combining INDIRECT with ROW and COLUMN

Data:

  • Cell A1: 5

  • Cell B2: A1

Formula:

excel
Copy
=INDIRECT("A" & ROW(B2))

Result: 5
Explanation: ROW(B2) returns 2, so the formula becomes INDIRECT("A2"), which references A2. However, since B2 contains A1, it indirectly references A1, which contains 5.

Example 3: Using INDIRECT with Sheet Names

Data:

  • Sheet1, Cell A1: 15

  • Sheet2, Cell A1: Sheet1!A1

Formula:

excel
Copy
=INDIRECT(Sheet2!A1)

Result: 15
Explanation: The formula references Sheet1!A1 through the text string in Sheet2!A1, returning the value 15.

Example 4: Dynamic Range with INDIRECT

Data:

  • Cell A1: 1

  • Cell A2: 2

  • Cell A3: 3

  • Cell B1: A1:A3

Formula:

excel
Copy
=SUM(INDIRECT(B1))

Result: 6
Explanation: INDIRECT(B1) converts the text A1:A3 into a range reference, and SUM adds up the values in that range.

Example 5: INDIRECT with Named Ranges

Data:

  • Named Range "Sales": A1:A3 (with values 102030)

  • Cell B1: Sales

Formula:

excel
Copy
=SUM(INDIRECT(B1))

Result: 60
Explanation: INDIRECT(B1) references the named range "Sales", and SUM adds up the values in that range.

Example 6: INDIRECT with Drop-Down List

Data:

  • Cell A1: 10

  • Cell A2: 20

  • Cell A3: 30

  • Cell B1: Drop-down list with options A1A2A3

Formula:

excel
Copy
=INDIRECT(B1)

Result: Depends on the selection in the drop-down list.
Explanation: If A2 is selected in the drop-down list, the formula returns 20.

Example 7: INDIRECT with R1C1 Reference Style

Data:

  • Cell A1: 100

  • Cell B1: R1C1

Formula:

excel
Copy
=INDIRECT(B1, FALSE)

Result: 100
Explanation: INDIRECT(B1, FALSE) uses R1C1 reference style, where R1C1 refers to row 1, column 1 (i.e., A1).

Example 8: INDIRECT with Concatenation

Data:

  • Cell A1: 50

  • Cell B1: A

  • Cell C1: 1

Formula:

excel
Copy
=INDIRECT(B1 & C1)

Result: 50
Explanation: B1 & C1 concatenates to A1, so INDIRECT("A1") returns the value in A1.

Example 9: INDIRECT with Multiple Sheets

Data:

  • Sheet1, Cell A1: 100

  • Sheet2, Cell A1: Sheet1!A1

Formula:

excel
Copy
=INDIRECT("Sheet2!A1")

Result: 100
Explanation: The formula references Sheet2!A1, which contains a reference to Sheet1!A1, so it returns the value 100.

Example 10: INDIRECT with Dynamic Column Reference

Data:

  • Cell A1: 10

  • Cell B1: 20

  • Cell C1: 30

  • Cell D1: B

Formula:

excel
Copy
=INDIRECT(D1 & "1")

Result: 20
Explanation: D1 & "1" concatenates to B1, so INDIRECT("B1") returns the value in B1.

Summary

The INDIRECT function is versatile and can be used in various scenarios to create dynamic references in Excel. Whether you're working with sheet names, named ranges, or dynamic cell references, INDIRECT can help you build more flexible and powerful spreadsheets.

CELL

 The CELL function in Excel is used to retrieve information about the formatting, location, or contents of a cell. However, it has limited options and does not directly expand to include data and formulas in the way you might be asking. Below, I’ll explain the CELL function and provide examples of how you can use it, along with workarounds to achieve expanded functionality for data and formulas.


Syntax of the CELL Function

excel
Copy
=CELL(info_type, [reference])
  • info_type: Specifies the type of information you want to retrieve (e.g., "address", "contents", "format").

  • reference: (Optional) The cell you want to get information about. If omitted, the function returns information about the last cell that was changed.


10 Common Uses of the CELL Function

  1. Get the Cell Address

    excel
    Copy
    =CELL("address", A1)

    Returns the address of the cell (e.g., $A$1).

  2. Get the Cell Contents

    excel
    Copy
    =CELL("contents", A1)

    Returns the value or text in the cell.

  3. Get the Column Number

    excel
    Copy
    =CELL("col", A1)

    Returns the column number of the cell (e.g., 1 for column A).

  4. Get the Row Number

    excel
    Copy
    =CELL("row", A1)

    Returns the row number of the cell (e.g., 1 for row 1).

  5. Get the File Path

    excel
    Copy
    =CELL("filename", A1)

    Returns the full file path, including the sheet name.

  6. Check if the Cell is Locked

    excel
    Copy
    =CELL("protect", A1)

    Returns 1 if the cell is locked, 0 if it’s not.

  7. Get the Format of the Cell

    excel
    Copy
    =CELL("format", A1)

    Returns a code representing the cell’s format (e.g., G for General, C2 for Currency with 2 decimal places).

  8. Get the Width of the Cell

    excel
    Copy
    =CELL("width", A1)

    Returns the width of the cell, rounded to the nearest integer.

  9. Check if the Cell Contains a Formula

    excel
    Copy
    =CELL("type", A1)

    Returns b if the cell is blank, l if it contains text, and v if it contains a value or formula.

  10. Get the Parentheses Format

    excel
    Copy
    =CELL("parentheses", A1)

    Returns 1 if the cell format includes parentheses for positive values, 0 otherwise.


Expanding CELL to Include Data and Formulas

The CELL function does not directly return formulas or expanded data. However, you can use other functions or techniques to achieve this:

  1. Display Formulas in Cells

    • Use the FORMULATEXT function to display the formula in a cell:

      excel
      Copy
      =FORMULATEXT(A1)
  2. Retrieve Data from a Range

    • Use INDEXMATCH, or VLOOKUP to retrieve data dynamically.

  3. Combine CELL with Other Functions

    • For example, to get the formula and address of a cell:

      excel
      Copy
      =CELL("address", A1) & " contains: " & FORMULATEXT(A1)
  4. Use VBA for Advanced Functionality

    • If you need more advanced functionality (e.g., extracting all formulas in a range), you can use VBA (Visual Basic for Applications).


Example: Combining CELL and FORMULATEXT

excel
Copy
=CELL("address", A1) & " contains: " & FORMULATEXT(A1)

This formula will return something like:

Copy
$A$1 contains: =SUM(B1:B10)

Limitations of the CELL Function

  • It does not provide detailed information about formulas or their results.

  • It cannot retrieve information about multiple cells at once.

  • It is not dynamic for array formulas or spilled ranges.


If you need more advanced functionality, consider using VBA or combining CELL with other Excel functions like FORMULATEXTINDEX, or INDIRECT.