Forum Discussion

mnirx's avatar
mnirx
Copper Contributor
Sep 20, 2022
Solved

how do I identify specific cell of column referenced in formula?

For illustration purposes, I created a super simplified version (Table 1) of what I am doing. The data set I am actually working with is much larger, thus, the need to identify which cells it is usin...
  • OliverScheurich's avatar
    Sep 20, 2022

    mnirx 

    Do you want to return the cells which add up to 72? In your example that would be cells B4, B5, B6, B7, B8, B9, B10, B11 and B12.

     

    With these lines of code you can return the cells. In the attached file you can click the button in cell J2. The cells are listed in column H. The macro works for any number of rows.

    Sub reference_cells()
    
    Dim i, j, k As Long
    
    Range("H:H").Clear
    i = Range("A" & Rows.Count).End(xlUp).Row
    k = 1
    For j = 1 To i
    
    If Cells(j, 1).Value > Cells(1, 4).Value Then
    Cells(k, 8).Value = "B" & j
    k = k + 1
    Else
    End If
    
    Next j
    
    End Sub

     

Resources