Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 16
Default Problem with a UDF im trying to write

I am trying to create a check register type spreadsheet, and wanting to use a
UDF,(or if you know another that will work too) to automaticly find the last
balance in the balance colum and return it in the cell at the bottom of the
page. Heres what im trying but it keeps locking up excel when i try to enter
it. I dont know if its the loop or the lack of an argument in the function
line.

Function EOMBal()
Dim a As Single
Range("G45").Select
a = 0
Do While a = 0
If a = 0 Then
ActiveCell.Offset(-1, 0).Select
End If
a = ActiveCell.Value
Loop
EOMBal = a
End Function

Im new to using functions and subs, and new to programing in general so any
advice would be appreaciated.
Thanks

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 772
Default Problem with a UDF im trying to write

This code works for me just fine, how are you calling it? What do you mean by
"when i try to enter it"
--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.


"CSUS_CE_Student" wrote:

I am trying to create a check register type spreadsheet, and wanting to use a
UDF,(or if you know another that will work too) to automaticly find the last
balance in the balance colum and return it in the cell at the bottom of the
page. Heres what im trying but it keeps locking up excel when i try to enter
it. I dont know if its the loop or the lack of an argument in the function
line.

Function EOMBal()
Dim a As Single
Range("G45").Select
a = 0
Do While a = 0
If a = 0 Then
ActiveCell.Offset(-1, 0).Select
End If
a = ActiveCell.Value
Loop
EOMBal = a
End Function

Im new to using functions and subs, and new to programing in general so any
advice would be appreaciated.
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default Problem with a UDF im trying to write

You don't need a UDF to do this:

Assume column F is the balance column.

To return the *LAST* numeric value from that column:

=LOOKUP(10^99,F:F)

Biff

"CSUS_CE_Student" wrote in message
...
I am trying to create a check register type spreadsheet, and wanting to use
a
UDF,(or if you know another that will work too) to automaticly find the
last
balance in the balance colum and return it in the cell at the bottom of
the
page. Heres what im trying but it keeps locking up excel when i try to
enter
it. I dont know if its the loop or the lack of an argument in the
function
line.

Function EOMBal()
Dim a As Single
Range("G45").Select
a = 0
Do While a = 0
If a = 0 Then
ActiveCell.Offset(-1, 0).Select
End If
a = ActiveCell.Value
Loop
EOMBal = a
End Function

Im new to using functions and subs, and new to programing in general so
any
advice would be appreaciated.
Thanks



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Problem with a UDF im trying to write

First, use Biff's suggestion. You'll be happier--it's quicker and easier to
implement.

But you have some problems in your code (a learning exercise only!).

You'd want to pass the range to look at to your function. Otherwise, excel
won't know when to calculate. (You could make the function calculate whenever
excel calculated, but your results could be one calculation behind.)

You can't select cells in a UDF called from a worksheet cell.

But something like this (again, don't use it) worked ok for me:

Option Explicit
Function EOMBal(myCol As Range)
Dim myVal As Double
With myCol.Columns(1).EntireColumn
myVal = .Cells(.Rows.Count, 1).End(xlUp).Value
End With
EOMBal = myVal
End Function

And you use it in a cell like:
=eombal(G:G)

======
But I would change Biff's suggestion:
=LOOKUP(10^99,F:F)
to
=LOOKUP(10^99,G:G)

<vbg


CSUS_CE_Student wrote:

I am trying to create a check register type spreadsheet, and wanting to use a
UDF,(or if you know another that will work too) to automaticly find the last
balance in the balance colum and return it in the cell at the bottom of the
page. Heres what im trying but it keeps locking up excel when i try to enter
it. I dont know if its the loop or the lack of an argument in the function
line.

Function EOMBal()
Dim a As Single
Range("G45").Select
a = 0
Do While a = 0
If a = 0 Then
ActiveCell.Offset(-1, 0).Select
End If
a = ActiveCell.Value
Loop
EOMBal = a
End Function

Im new to using functions and subs, and new to programing in general so any
advice would be appreaciated.
Thanks


--

Dave Peterson
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
how do I write a 6 day schedule? dcoleman Excel Discussion (Misc queries) 1 August 20th 06 11:43 AM
How do you write a T with a bar on it? sheezyspearean Excel Discussion (Misc queries) 1 September 15th 05 03:43 PM
help me write function? Zach Excel Worksheet Functions 5 August 3rd 05 03:12 PM
is it possible to execute write to the fields in another .xsl form a macro in another .xsl? e.g. some way to load another .xsl into an .xsl macro and write to its data? Daniel Excel Worksheet Functions 1 June 23rd 05 11:38 PM
How to I write a UDF? Dr. Juzzy Excel Discussion (Misc queries) 1 January 30th 05 02:17 PM


All times are GMT +1. The time now is 09:02 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"