Question : How do I pass a cell reference through to my function code instead of the cell contents

I can usually figure out ways to do most things in excel and while the solutions may not be elegant they work.

This has me stumped

I am tring to program a function for using within the excel sheet. The function I have called latest  will in theory for the start cell chosen check to see if the cell in in the column with the right title (in my spread sheet ASP ) then check to see if the cell has a value or not. If it finds a value it returns it to the function and stops else moves progresivley to the right.

The Problem

I can't figur out how to carry the cell refrence though to the function whatever I try the starting cell shoesn when the user  inputs the arguments always returns the value of the start cell ans not it's Address I I want AN4 to come though ans I get the value in AN4 instead .

I appologize if this is very trivial but 4 hour later of internet searches and plying in the vb help and I am no further.

Also the soloution must allow the fomula to be copied down in the spread sheet and still return the correct numbers

Thanks in advance for suggestions

Regards to all

from

David

( an excel hack and amateur)
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
Function Latest(Columnheading As String, headingrow As Integer, startcell As Range)
 
Dim CH As String
Dim CHR As Integer
Dim DIR As Integer
Dim N As Integer
Dim X As Variant
 
CH = Columnheading
 
X = Range(startcell)
Range(X).Select
Range(X).Activate
N = Range(X).Row - headingrow
I = Range(X).Column
c = 0
Do Until c = I
 
If ActiveCell.Offset(-N, -c).Value = CH Then
If ActiveCell.Offset(N, -c).Value <> 0 Then
Latest = ActiveCell.Offset(N, -c).Value
End
Else
End If
Else
c = c + 1
End If
Loop
 
End Function

Answer : How do I pass a cell reference through to my function code instead of the cell contents

Try this:

Public Function ShowReference(S As Range)

    MsgBox S.Address

End Function
Random Solutions  
 
programming4us programming4us