Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Inserting a function



Howdie,

I want to insert the function below into VBA.

I create a new module and paste it in, but how do I run it, or see the
results of it?

Thanks

Darin


Function fzLastValue(RangeId As Variant, Optional byColumn As Boolean =
True)
Dim cLast As Long
Dim oLast As Range

Application.Volatile

If byColumn Then
cLast = Cells(Rows.Count, RangeId).End(xlUp).Row
Set oLast = Range(RangeId & cLast)
Else
cLast = Cells(RangeId, Columns.Count).End(xlToLeft).Column
Set oLast = Cells(RangeId, cLast)
End If

fzLastValue = oLast.Value

End Function


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Inserting a function

Darin ,

Had to make a couple of changes to make it work for me, but you use with a
simple =fzLastValue(A1:B10) in a worksheet

Function fzLastValue(RangeId As Variant, Optional byColumn As Boolean =
True)
Dim cLast As Long
Dim oLast As Range

Application.Volatile

If byColumn Then
cLast = Cells(Rows.Count, RangeId.Column).End(xlUp).Row
Set oLast = Cells(cLast, RangeId.Column)
Else
cLast = Cells(RangeId.Row, Columns.Count).End(xlToLeft).Column
Set oLast = Cells(RangeId.Row, cLast)
End If

fzLastValue = oLast.Value

End Function



--

HTH

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


"Darin Kramer" wrote in message
...


Howdie,

I want to insert the function below into VBA.

I create a new module and paste it in, but how do I run it, or see the
results of it?

Thanks

Darin


Function fzLastValue(RangeId As Variant, Optional byColumn As Boolean =
True)
Dim cLast As Long
Dim oLast As Range

Application.Volatile

If byColumn Then
cLast = Cells(Rows.Count, RangeId).End(xlUp).Row
Set oLast = Range(RangeId & cLast)
Else
cLast = Cells(RangeId, Columns.Count).End(xlToLeft).Column
Set oLast = Cells(RangeId, cLast)
End If

fzLastValue = oLast.Value

End Function


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Inserting a function

Hi
you have to enter this function for example in a cell. e.g.
=fzLastValue(2)
for column B

"Darin Kramer" wrote:



Howdie,

I want to insert the function below into VBA.

I create a new module and paste it in, but how do I run it, or see the
results of it?

Thanks

Darin


Function fzLastValue(RangeId As Variant, Optional byColumn As Boolean =
True)
Dim cLast As Long
Dim oLast As Range

Application.Volatile

If byColumn Then
cLast = Cells(Rows.Count, RangeId).End(xlUp).Row
Set oLast = Range(RangeId & cLast)
Else
cLast = Cells(RangeId, Columns.Count).End(xlToLeft).Column
Set oLast = Cells(RangeId, cLast)
End If

fzLastValue = oLast.Value

End Function


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Inserting a function

Hi
should be:
=fzLastValue(B1)


"Frank Kabel" wrote:

Hi
you have to enter this function for example in a cell. e.g.
=fzLastValue(2)
for column B

"Darin Kramer" wrote:



Howdie,

I want to insert the function below into VBA.

I create a new module and paste it in, but how do I run it, or see the
results of it?

Thanks

Darin


Function fzLastValue(RangeId As Variant, Optional byColumn As Boolean =
True)
Dim cLast As Long
Dim oLast As Range

Application.Volatile

If byColumn Then
cLast = Cells(Rows.Count, RangeId).End(xlUp).Row
Set oLast = Range(RangeId & cLast)
Else
cLast = Cells(RangeId, Columns.Count).End(xlToLeft).Column
Set oLast = Cells(RangeId, cLast)
End If

fzLastValue = oLast.Value

End Function


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Inserting a function



Unfortunately I get an #/Value error when pasting that into the workbook
VBA module, and then within the worksheet referncing a cell (say b11 =
fzlastvalue(A1:b10)

Ideas most welcome... Im just trying to select a block of text....(size
not always known..)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Inserting a function


Thats what I got in the cell fzLastValue(B1) and still no result??? Im
sure its something really simple...? if it works on yours is it possible
to send me the blank workbook?

Thanks

D


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Inserting a function

Hi Darin

did you do insert / module and paste the function in there - or did you
paste the function into "ThisWorkbook" - the former option works for me.

BTW i used Bob's version of the code.

Cheers
JulieD

"Darin Kramer" wrote in message
...


Unfortunately I get an #/Value error when pasting that into the workbook
VBA module, and then within the worksheet referncing a cell (say b11 =
fzlastvalue(A1:b10)

Ideas most welcome... Im just trying to select a block of text....(size
not always known..)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Inserting a function



Hi Julie,

If i put it in the former i get a #/Value error
IF I put it in the latter i get a #/Name error,

So whatever I do I seem to be stuck!!! no idea why.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Inserting a function

Hi Darin

i've emailed you a sample workbook (to the hotmail address) with the code in
it - seems to work okay for me ... does it work on your system?

Cheers
JulieD

"Darin Kramer" wrote in message
...


Hi Julie,

If i put it in the former i get a #/Value error
IF I put it in the latter i get a #/Name error,

So whatever I do I seem to be stuck!!! no idea why.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default Inserting a function

Hi Darin

try

Function fzLastValue(RangeId As Variant, Optional byColumn As Boolean =
True)
Dim cLast As Long
Dim dLast As Long
Application.Volatile

If byColumn Then
cLast = Cells(Rows.Count, RangeId.Column).End(xlUp).Row
dLast = Cells(cLast, Columns.Count).End(xlToLeft).Column
Else
cLast = Cells(Rows.Count, RangeId.Column).End(xlUp).Row
dLast = 1
End If

fzLastValue = Cells(cLast, dLast).Value

End Function

Cheers
julieD

"JulieD" wrote in message
...
Hi Darin

i've emailed you a sample workbook (to the hotmail address) with the code
in it - seems to work okay for me ... does it work on your system?

Cheers
JulieD

"Darin Kramer" wrote in message
...


Hi Julie,

If i put it in the former i get a #/Value error
IF I put it in the latter i get a #/Name error,

So whatever I do I seem to be stuck!!! no idea why.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





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
Inserting dates function ArthurN Excel Worksheet Functions 4 January 11th 09 02:37 PM
Inserting a function into a worksheet Rich D Excel Discussion (Misc queries) 1 February 9th 07 05:36 PM
Inserting Pictures with IF function DrewNov Excel Worksheet Functions 0 August 25th 05 07:58 PM
Inserting an AutoDate Function MissTrish New Users to Excel 1 May 26th 05 06:02 PM
Inserting a SUM Function Ken Loomis Excel Programming 2 October 12th 04 07:34 AM


All times are GMT +1. The time now is 03:59 AM.

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

About Us

"It's about Microsoft Excel"