Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
bac bac is offline
external usenet poster
 
Posts: 76
Default Result posts before Function executes

XP Pro, Office 2003 Pro
I"ve never run into this before. I've got a user defined function:

Function fn_SummaryPage(in_date As Date) As Double
Dim nd_row As Integer, is_Rt As Integer

fn_SummaryPage = 0

With Sheets("DATA")

.Select
.Cells(1, 1).Select
ActiveCell.SpecialCells(xlLastCell).Select
nd_row = Selection.Row

For i = 1 To nd_row
If .Cells(i, "F").Value = in_date Then
is_Rt = fn_FindRT(.Cells(i, "S"))
fn_SummaryPage = fn_SummaryPage + (is_Rt * .Cells(i, "K"))
End If
Next i
End With

End Function

The function is entered in an equation on sheets("Summary") (as: =
fn_SummaryPage(A4) where A4 is a relevant date. When I calculate, the value
in the cell on sheets("Summary") goes to #VALUE.
I've stepped thru the function and found this occurs as soon as the
.Cells(1, 1).Select
line executes (So as soon as the function selects a cell "off sheet", the
function terminates and returns "#VALUE" in the cell on sheets("Summary")
where the formula is.

I cannot use sumproduct or Sum + If because the data on sheets("DATA") is
mixed format and has multiple sections with various length sections and blank
rows between them.

TIA

BAC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Result posts before Function executes

A function used in a worksheet can not change the selection. Also, I don't
think special cells works properly when the function is used in a worksheet.
Here is a fix:

Function fn_SummaryPage(in_date As Date) As Double
Dim nd_row As Long, is_Rt As Long
Dim rng as Range
fn_SummaryPage = 0

With Sheets("DATA")


set rng = .Cells(rows.count,"F").End(xlup)
nd_row = rng.Row

For i = 1 To nd_row
If .Cells(i, "F").Value = in_date Then
is_Rt = fn_FindRT(.Cells(i, "S"))
fn_SummaryPage = fn_SummaryPage + (is_Rt * .Cells(i, "K"))
End If
Next i
End With

End Function

--
Regards,
Tom Ogilvy


"BAC" wrote:

XP Pro, Office 2003 Pro
I"ve never run into this before. I've got a user defined function:

Function fn_SummaryPage(in_date As Date) As Double
Dim nd_row As Integer, is_Rt As Integer

fn_SummaryPage = 0

With Sheets("DATA")

.Select
.Cells(1, 1).Select
ActiveCell.SpecialCells(xlLastCell).Select
nd_row = Selection.Row

For i = 1 To nd_row
If .Cells(i, "F").Value = in_date Then
is_Rt = fn_FindRT(.Cells(i, "S"))
fn_SummaryPage = fn_SummaryPage + (is_Rt * .Cells(i, "K"))
End If
Next i
End With

End Function

The function is entered in an equation on sheets("Summary") (as: =
fn_SummaryPage(A4) where A4 is a relevant date. When I calculate, the value
in the cell on sheets("Summary") goes to #VALUE.
I've stepped thru the function and found this occurs as soon as the
.Cells(1, 1).Select
line executes (So as soon as the function selects a cell "off sheet", the
function terminates and returns "#VALUE" in the cell on sheets("Summary")
where the formula is.

I cannot use sumproduct or Sum + If because the data on sheets("DATA") is
mixed format and has multiple sections with various length sections and blank
rows between them.

TIA

BAC

  #3   Report Post  
Posted to microsoft.public.excel.programming
bac bac is offline
external usenet poster
 
Posts: 76
Default Result posts before Function executes

Thanx...That did it!

"Tom Ogilvy" wrote:

A function used in a worksheet can not change the selection. Also, I don't
think special cells works properly when the function is used in a worksheet.
Here is a fix:

Function fn_SummaryPage(in_date As Date) As Double
Dim nd_row As Long, is_Rt As Long
Dim rng as Range
fn_SummaryPage = 0

With Sheets("DATA")


set rng = .Cells(rows.count,"F").End(xlup)
nd_row = rng.Row

For i = 1 To nd_row
If .Cells(i, "F").Value = in_date Then
is_Rt = fn_FindRT(.Cells(i, "S"))
fn_SummaryPage = fn_SummaryPage + (is_Rt * .Cells(i, "K"))
End If
Next i
End With

End Function

--
Regards,
Tom Ogilvy


"BAC" wrote:

XP Pro, Office 2003 Pro
I"ve never run into this before. I've got a user defined function:

Function fn_SummaryPage(in_date As Date) As Double
Dim nd_row As Integer, is_Rt As Integer

fn_SummaryPage = 0

With Sheets("DATA")

.Select
.Cells(1, 1).Select
ActiveCell.SpecialCells(xlLastCell).Select
nd_row = Selection.Row

For i = 1 To nd_row
If .Cells(i, "F").Value = in_date Then
is_Rt = fn_FindRT(.Cells(i, "S"))
fn_SummaryPage = fn_SummaryPage + (is_Rt * .Cells(i, "K"))
End If
Next i
End With

End Function

The function is entered in an equation on sheets("Summary") (as: =
fn_SummaryPage(A4) where A4 is a relevant date. When I calculate, the value
in the cell on sheets("Summary") goes to #VALUE.
I've stepped thru the function and found this occurs as soon as the
.Cells(1, 1).Select
line executes (So as soon as the function selects a cell "off sheet", the
function terminates and returns "#VALUE" in the cell on sheets("Summary")
where the formula is.

I cannot use sumproduct or Sum + If because the data on sheets("DATA") is
mixed format and has multiple sections with various length sections and blank
rows between them.

TIA

BAC

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
Unable to read own posts or replied Posts Killer Excel Discussion (Misc queries) 3 June 6th 07 10:23 PM
For Loop only executes with F8 Sisilla[_2_] Excel Programming 2 October 10th 06 08:57 PM
SAveAs executes combobox code Alan Lyall Excel Programming 3 June 9th 04 12:52 AM
excel executes only a part of a macro mgr[_2_] Excel Programming 2 January 15th 04 07:18 AM
Count # of Times Sub Executes Mike[_32_] Excel Programming 1 July 15th 03 03:27 PM


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