I have searched high and low across the entire internet for this, but I can’t seem to find an answer. Within an Excel VBA script, I want to load a variable from the value of a cell on the spreadsheet. The issue is that I want to specify that cell as being on the same row as the cell that is using this VBA formula, but with a specific column. Basically I want within the script to load the value from column “C” of the active row.
In a particular cell, I’ll enter the formula =myfunc()
If I use
varName = ActiveCell.Offset(0, -7).Value2 I’ll end up with relative row and columns.
If I use
varName = ActiveCell.Cells(1, 3).Value2, I get absolute row and columns.
I want to load the value from the cell in column “C” (aka 3) of the current row containing “=myfunc()” into varName regardless the row or column of the cell containing this formula.
For a start, don’t use
ActiveCell – that’s not necessarily the cell with the formula
varName = Application.Caller.EntireRow.Cells(3).Value
should work. Or you can use
Application.ThisCell in place of