Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
Can I somehow determine, in which column (A,B,C,...) a selfmade function is called? Or: Can I tell the function, placed f.e. in cell C1, to loop through the column left (in this example B) of it? thanks lot for help materphilch |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Application.Caller.Address
will get the calling cell address. The second part could be done with For Each cell In Range(Application.Caller.Address).Offset(0,-1).EntireColumn 'do stuff on cell Next cell -- HTH RP (remove nothere from the email address if mailing direct) "masterphilch" wrote in message ... Hi Can I somehow determine, in which column (A,B,C,...) a selfmade function is called? Or: Can I tell the function, placed f.e. in cell C1, to loop through the column left (in this example B) of it? thanks lot for help materphilch |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
thanks for help.
But it seems as if the For...Next doesn't work. The program does the loop just once. any idea what could be wrong? the code: For Each cell In Range(Application.Caller.Address).Offset(0,-1).EntireColumn 'do something Next cell thanks masterphilch Bob Phillips wrote: Application.Caller.Address will get the calling cell address. The second part could be done with For Each cell In Range(Application.Caller.Address).Offset(0,-1).EntireColumn 'do stuff on cell Next cell |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you are using it as a UDF, you cannot change any cell contents, just
doesn't work -- HTH RP (remove nothere from the email address if mailing direct) "masterphilch" wrote in message ... thanks for help. But it seems as if the For...Next doesn't work. The program does the loop just once. any idea what could be wrong? the code: For Each cell In Range(Application.Caller.Address).Offset(0,-1).EntireColumn 'do something Next cell thanks masterphilch Bob Phillips wrote: Application.Caller.Address will get the calling cell address. The second part could be done with For Each cell In Range(Application.Caller.Address).Offset(0,-1).EntireColumn 'do stuff on cell Next cell |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
So I can't refer relatively to any cell from the position of my
self-made-function? Wahts a UDF? greez Bob Phillips wrote: If you are using it as a UDF, you cannot change any cell contents, just doesn't work |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
A UDF is a user defined function, which is a VBA function that you use in a
worksheet. You can read any cells on the worksheet, nut you can't write to them, just return a value to the calling cell. -- HTH RP (remove nothere from the email address if mailing direct) "masterphilch" wrote in message ... So I can't refer relatively to any cell from the position of my self-made-function? Wahts a UDF? greez Bob Phillips wrote: If you are using it as a UDF, you cannot change any cell contents, just doesn't work |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
first, application.Caller returns a rng reference, so you don't want to
convert it to an string address, the convert it back to a range. The second is that EntireColumn is a singe entity, so there is nothing to loop through Just to illustrate in the immediate window: ? ActiveCell.EntireColumn.Count 1 so you have a column, not 65536 cells Another thing is that it takes forever to loop through 65536 cells - surely you don't want to do that. What do you want to do. Perhaps set rng = Application.Caller set r = rng.offset(0,-1) set r = range(cells(1,r.column),cells(rows.count,r.column) .End(xlup)) For Each cell r Next If you do want the entire column then For Each cell In Range(Application.Caller.Address) _ .Offset(0,-1).EntireColumn.Cells 'do something Next cell as Bob said, in a UDF used in a worksheet as a formula, you can't change values or formatting in other cells, but you can read their values or formating. -- Regards, Tom Ogilvy "masterphilch" wrote in message ... thanks for help. But it seems as if the For...Next doesn't work. The program does the loop just once. any idea what could be wrong? the code: For Each cell In Range(Application.Caller.Address).Offset(0,-1).EntireColumn 'do something Next cell thanks masterphilch Bob Phillips wrote: Application.Caller.Address will get the calling cell address. The second part could be done with For Each cell In Range(Application.Caller.Address).Offset(0,-1).EntireColumn 'do stuff on cell Next cell |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
thanks Tom!
that's what I'd call a good reply! What I actually want to do: Check the number of filled rows, left of the cell I entered the function. And as soon as i got the number (perhaps I can determine the number of filled cells in that row as limit [with a loop]) of filled cells, I want to check, which one's got the biggest value... I could add an argument to the function, force the user to enter a range. But that wouldn't be a challenge ;) greez for help or something... masterphil Tom Ogilvy wrote: first, application.Caller returns a rng reference, so you don't want to convert it to an string address, the convert it back to a range. The second is that EntireColumn is a singe entity, so there is nothing to loop through Just to illustrate in the immediate window: ? ActiveCell.EntireColumn.Count 1 so you have a column, not 65536 cells Another thing is that it takes forever to loop through 65536 cells - surely you don't want to do that. What do you want to do. Perhaps set rng = Application.Caller set r = rng.offset(0,-1) set r = range(cells(1,r.column),cells(rows.count,r.column) .End(xlup)) For Each cell r Next If you do want the entire column then For Each cell In Range(Application.Caller.Address) _ .Offset(0,-1).EntireColumn.Cells 'do something Next cell as Bob said, in a UDF used in a worksheet as a formula, you can't change values or formatting in other cells, but you can read their values or formating. |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What I actually want to do: Check the number of filled rows, left of the
cell I entered the function. And as soon as i got the number (perhaps I can determine the number of filled cells in that row as limit [with a loop]) of filled cells, I want to check, which one's got the biggest value... I could add an argument to the function, force the user to enter a range. But that wouldn't be a challenge ;) greez for help or something... masterphil Tom Ogilvy wrote: first, application.Caller returns a rng reference, so you don't want to convert it to an string address, the convert it back to a range. The second is that EntireColumn is a singe entity, so there is nothing to loop through Just to illustrate in the immediate window: ? ActiveCell.EntireColumn.Count 1 so you have a column, not 65536 cells Another thing is that it takes forever to loop through 65536 cells - surely you don't want to do that. What do you want to do. Perhaps set rng = Application.Caller set r = rng.offset(0,-1) set r = range(cells(1,r.column),cells(rows.count,r.column) .End(xlup)) For Each cell r Next If you do want the entire column then For Each cell In Range(Application.Caller.Address) _ .Offset(0,-1).EntireColumn.Cells 'do something Next cell as Bob said, in a UDF used in a worksheet as a formula, you can't change values or formatting in other cells, but you can read their values or formating. |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
set rng = Application.Caller
set r = rng.offset(0,-1) set r = range(cells(1,r.column),cells(rows.count,r.column) .End(xlup)) numFilled = Application.CountA(r) maxval = Application.Max(r) If you just want the count of numbers in that range rather than all filled cells, use Count rather than CountA -- Regards, Tom Ogilvy "masterphilch" wrote in message ... What I actually want to do: Check the number of filled rows, left of the cell I entered the function. And as soon as i got the number (perhaps I can determine the number of filled cells in that row as limit [with a loop]) of filled cells, I want to check, which one's got the biggest value... I could add an argument to the function, force the user to enter a range. But that wouldn't be a challenge ;) greez for help or something... masterphil Tom Ogilvy wrote: first, application.Caller returns a rng reference, so you don't want to convert it to an string address, the convert it back to a range. The second is that EntireColumn is a singe entity, so there is nothing to loop through Just to illustrate in the immediate window: ? ActiveCell.EntireColumn.Count 1 so you have a column, not 65536 cells Another thing is that it takes forever to loop through 65536 cells - surely you don't want to do that. What do you want to do. Perhaps set rng = Application.Caller set r = rng.offset(0,-1) set r = range(cells(1,r.column),cells(rows.count,r.column) .End(xlup)) For Each cell r Next If you do want the entire column then For Each cell In Range(Application.Caller.Address) _ .Offset(0,-1).EntireColumn.Cells 'do something Next cell as Bob said, in a UDF used in a worksheet as a formula, you can't change values or formatting in other cells, but you can read their values or formating. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
ISBLANK function not working when cell is blank dut to function re | Excel Discussion (Misc queries) | |||
Copy Excel Function from a Cell Through a Function | Excel Worksheet Functions | |||
I want result of a function in the cell and not the function itsel | Excel Worksheet Functions | |||
Can function in one cell change value or function in another cell? | Excel Worksheet Functions | |||
Custom Function: Detecting the cell the function is used in | Excel Programming |