Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default lastcell in thiscolumn function error

Cheers all,
I wrote a UFD to return address of last cell of a column of data. The
function takes a cell reference in the column of interest as its
argument.

For example The data is in a range on worksheet1 B2:D6, lastcellref(b2)
should return $b$6

the Function code is:

Function lastcellref(thiscolumn As Variant)
Dim lastcell As Variant
Set lastcell = Cells(1001, thiscolumn.Column).End(xlUp)
Set lastcellref = lastcell.AddressLocal(RowAbsolute:=True,
columnabsolute:=True)
End Function

when I run this function, I get Run time error 424, object required.
what am I doing wrong?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default lastcell in thiscolumn function error

Function lastcellref(thiscolumn As Variant)
Dim lastcell As Variant
Set lastcell = Cells(Rows.Count, thiscolumn.Column).End(xlUp)
lastcellref = lastcell.AddressLocal(True, True)
End Function



--

HTH

RP
(remove nothere from the email address if mailing direct)


"deano" wrote in message
ups.com...
Cheers all,
I wrote a UFD to return address of last cell of a column of data. The
function takes a cell reference in the column of interest as its
argument.

For example The data is in a range on worksheet1 B2:D6, lastcellref(b2)
should return $b$6

the Function code is:

Function lastcellref(thiscolumn As Variant)
Dim lastcell As Variant
Set lastcell = Cells(1001, thiscolumn.Column).End(xlUp)
Set lastcellref = lastcell.AddressLocal(RowAbsolute:=True,
columnabsolute:=True)
End Function

when I run this function, I get Run time error 424, object required.
what am I doing wrong?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default lastcell in thiscolumn function error


Hello Deano,

Here is the amended code...

Function lastcellref(thiscolumn As Range)

Dim lastcell As Variant

With thiscolumn.Parent
lastcell = .Cells(.Rows.Count, Rng.Column).End(xlUp).Address(True,
True)
End With

lastcellref = lastcell

End Function

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=487877

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default lastcell in thiscolumn function error

Here is my original thread:

Cheers all,
I wrote a UFD to return address of last cell of a column of data. The
function takes a cell reference in the column of interest as its
argument.


For example The data is in a range on worksheet1 B2:D6, lastcellref(b2)

should return $b$6


the Function code is:


Function lastcellref(thiscolumn As Variant)
Dim lastcell As Variant
Set lastcell = Cells(1001, thiscolumn.Column).End(xlUp)
Set lastcellref = lastcell.AddressLocal(RowAbsolute:=True,
columnabsolute:=True)
End Function


when I run this function, I get Run time error 424, object required.
what am I doing wrong?

Bob proposed that I modify code as below,

Function lastcellref(thiscolumn As Variant)
Dim lastcell As Variant
Set lastcell = Cells(Rows.Count, thiscolumn.Column).End(xlUp)
lastcellref = lastcell.AddressLocal(True, True)
End Function


Bob, when i run lastcellref(b2), I still get Run time error 424, object
required.

Leith propsed to midify it as below,

Function lastcellref(thiscolumn As Range)
Dim lastcell As Variant
With thiscolumn.Parent
lastcell = .Cells(.Rows.Count, Rng.Column).End(xlUp).Address(True,
True)
End With
lastcellref = lastcell
End Function

when I run lastcellref(b2), I get Complile error, Byref argument type
mismatch

Could you please take a closer look, thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default lastcell in thiscolumn function error

Deano,

I know what is happeing. You are calling these functions from VBA, but you
are using Excel syntax. On a worksheet you could use =lastcellref(B2) and it
would work fine, but in VBA you have to use
myVar = lastcellref(Range("B2"))

--

HTH

RP
(remove nothere from the email address if mailing direct)


"deano" wrote in message
ups.com...
Here is my original thread:

Cheers all,
I wrote a UFD to return address of last cell of a column of data. The
function takes a cell reference in the column of interest as its
argument.


For example The data is in a range on worksheet1 B2:D6, lastcellref(b2)

should return $b$6


the Function code is:


Function lastcellref(thiscolumn As Variant)
Dim lastcell As Variant
Set lastcell = Cells(1001, thiscolumn.Column).End(xlUp)
Set lastcellref = lastcell.AddressLocal(RowAbsolute:=True,
columnabsolute:=True)
End Function


when I run this function, I get Run time error 424, object required.
what am I doing wrong?

Bob proposed that I modify code as below,

Function lastcellref(thiscolumn As Variant)
Dim lastcell As Variant
Set lastcell = Cells(Rows.Count, thiscolumn.Column).End(xlUp)
lastcellref = lastcell.AddressLocal(True, True)
End Function


Bob, when i run lastcellref(b2), I still get Run time error 424, object
required.

Leith propsed to midify it as below,

Function lastcellref(thiscolumn As Range)
Dim lastcell As Variant
With thiscolumn.Parent
lastcell = .Cells(.Rows.Count, Rng.Column).End(xlUp).Address(True,
True)
End With
lastcellref = lastcell
End Function

when I run lastcellref(b2), I get Complile error, Byref argument type
mismatch

Could you please take a closer look, thanks





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default lastcell in thiscolumn function error

http://groups.google.com/group/micro...030e190f30173b

Bob,

1. Yes The UDF works fine in the worksheet by using =lastcellref(B2)
but just like you said, you have to use ?lastcellref(Range("b2")) for
it to work in the immediate window. But why is that?

2. I tried the UDF in the worksheet using both my original version and
yours and they both work equally well with no "Run time error 424,
object required. " Why did it not work before ?

Function lastcellref(thiscolumn As Variant)
Dim thiscolumn As Variant
Set lastcell = Cells(1001, thiscolumn.Column).End(xlUp)
Set lastcellref = lastcell.AddressLocal(RowAbsolute:=True,
columnabsolute:=True) ' this is my original version
'Set lastcell = Cells(Rows.Count, thiscolumn.Column).End(xlUp) ' this
is Bob's version
End Function

thanks

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
IF Function error #VALUE Pat[_7_] Excel Worksheet Functions 1 December 6th 11 10:35 PM
Possible error in MOD function Peter K[_2_] Excel Worksheet Functions 2 February 23rd 08 01:53 AM
Excel 2007 BUG UsedRange/LastCell differences with Excel2003. keepITcool Excel Discussion (Misc queries) 2 May 31st 06 06:18 PM
Dynamic LastCell James Agostinho Excel Programming 4 February 22nd 04 09:08 PM
LastCell Function David Excel Programming 6 December 5th 03 02:51 PM


All times are GMT +1. The time now is 04:29 AM.

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"