Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default get cell of function

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default get cell of function

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ISBLANK function not working when cell is blank dut to function re mcmilja Excel Discussion (Misc queries) 9 May 7th 23 03:43 AM
Copy Excel Function from a Cell Through a Function Sheikh Saadi Excel Worksheet Functions 0 October 15th 09 04:22 PM
I want result of a function in the cell and not the function itsel Rana Excel Worksheet Functions 4 July 2nd 07 06:20 AM
Can function in one cell change value or function in another cell? me Excel Worksheet Functions 4 February 27th 06 01:04 PM
Custom Function: Detecting the cell the function is used in g-boy Excel Programming 2 June 11th 05 06:46 PM


All times are GMT +1. The time now is 12:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"