ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calling Cell (or ROW() and COLUMN() in VBA) (https://www.excelbanter.com/excel-programming/353120-calling-cell-row-column-vba.html)

scott

Calling Cell (or ROW() and COLUMN() in VBA)
 
I am new to VBA and need what I would think would be something easy, but I
have not been able to work out how to do it.

I have a macro that sums all values from the cell the macro is in to some
limit. At present I need to enter "=ITEMSUM(ROW(),COLUMN())" in the cell.
So I know where I am being called from. What I want to be able to enter in
the cell is "=ITEMSUM()" and inside ItemSum get the equivalent of ROW() and
COLUMN(). How can I do this?

Jim Thomlinson[_5_]

Calling Cell (or ROW() and COLUMN() in VBA)
 
I think this is what you are looking for.

Public Function Whatever() As String
'Application.volatile 'if you need it to recalc no matter what changes
With Application.Caller
Whatever = "Row " & .Row & " and column " & .Column
End With
End Function

insert this in a standard code module and call it from a cell. It will
return the row and column of the cell that it is in...
--
HTH...

Jim Thomlinson


"Scott" wrote:

I am new to VBA and need what I would think would be something easy, but I
have not been able to work out how to do it.

I have a macro that sums all values from the cell the macro is in to some
limit. At present I need to enter "=ITEMSUM(ROW(),COLUMN())" in the cell.
So I know where I am being called from. What I want to be able to enter in
the cell is "=ITEMSUM()" and inside ItemSum get the equivalent of ROW() and
COLUMN(). How can I do this?


scott

Calling Cell (or ROW() and COLUMN() in VBA)
 
Thanks Jim. Application.Caller was exactly the thing I was hunting for

"Jim Thomlinson" wrote:

I think this is what you are looking for.

Public Function Whatever() As String
'Application.volatile 'if you need it to recalc no matter what changes
With Application.Caller
Whatever = "Row " & .Row & " and column " & .Column
End With
End Function

insert this in a standard code module and call it from a cell. It will
return the row and column of the cell that it is in...
--
HTH...

Jim Thomlinson


"Scott" wrote:

I am new to VBA and need what I would think would be something easy, but I
have not been able to work out how to do it.

I have a macro that sums all values from the cell the macro is in to some
limit. At present I need to enter "=ITEMSUM(ROW(),COLUMN())" in the cell.
So I know where I am being called from. What I want to be able to enter in
the cell is "=ITEMSUM()" and inside ItemSum get the equivalent of ROW() and
COLUMN(). How can I do this?



All times are GMT +1. The time now is 07:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com