LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Help me with this UDF? Complex nested IFs...

Hi guys,

Thanks for looking at this. I have a custom function written that has
performed flawlessly up until about a minute ago when I added one more
line.

Here is the non-working version I am dealing with right now:

(edit - cliffnotes: I need RegCell1 to return itself as text - instead,
it returns as a date/time, when all other regcells, if returned, come
out as text. Makes it impossible to use in Access. Please read on for
more details)

****************

Function SDRank(PreviousBus, CurrentBus, InspectionNumber, CVIPCell,
RegCell1, RegCell2, RegCell3, RegCell4, RegCell5, RegCell6, RegCell7,
RegCell8, RegCell9, RegCell10, RegCell11, RegCell12, RegCellneg1,
RegCellneg2, RegCellneg3, RegCellneg4, RegCellneg5, RegCellneg6,
RegCellneg7, RegCellneg8, RegCellneg9, RegCellneg10, RegCellneg11) As
String

If InspectionNumber = 1 Then

If PreviousBus < CurrentBus Then
If CVIPCell < RegCell1 And (RegCell1 - CVIPCell) = 32 Then
SDRank = "OverDue"
Else
If CVIPCell < RegCell1 And (RegCell1 - CVIPCell) <= 31 Then
SDRank = RegCell1
Else
If CVIPCell RegCell1 And CVIPCell < RegCell2 Then
SDRank = RegCell2
Else
If CVIPCell RegCell2 And CVIPCell < RegCell3 Then
SDRank = RegCell3
Else
If CVIPCell RegCell3 And CVIPCell < RegCell4 Then
SDRank = RegCell4
Else
If CVIPCell RegCell4 And CVIPCell < RegCell5
Then
SDRank = RegCell5
Else
If CVIPCell RegCell5 And CVIPCell <
RegCell6 Then
SDRank = RegCell6
Else
If CVIPCell RegCell6 And CVIPCell <
RegCell7 Then
SDRank = RegCell7
Else
If CVIPCell RegCell7 And CVIPCell
< RegCell8 Then
SDRank = RegCell8
Else
If CVIPCell RegCell8 And
CVIPCell < RegCell9 Then
SDRank = RegCell9
Else
If CVIPCell RegCell9 And
CVIPCell < RegCell10 Then
SDRank = RegCell10
Else
If CVIPCell RegCell10
And CVIPCell < RegCell11 Then
SDRank = RegCell11
Else
If CVIPCell
RegCell11 And CVIPCell < RegCell12 Then
SDRank = RegCell12
Else
SDRank = ""
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
Else
If CVIPCell < RegCell1 And (RegCell1 - CVIPCell) = 32 Then
SDRank = "OverDue"
Else
If CVIPCell < RegCell1 And (RegCell1 - CVIPCell) <= 31 Then
SDRank = RegCell1
Else
If CVIPCell RegCell1 And CVIPCell < RegCell2 Then
SDRank = RegCell2
Else
If CVIPCell RegCell2 And CVIPCell < RegCell3 Then
SDRank = RegCell3
Else
If CVIPCell RegCell3 And CVIPCell < RegCell4 Then
SDRank = RegCell4
Else
If CVIPCell RegCell4 And CVIPCell < RegCell5
Then
SDRank = RegCell5
Else
If CVIPCell RegCell5 And CVIPCell <
RegCell6 Then
SDRank = RegCell6
Else
If CVIPCell RegCell6 And CVIPCell <
RegCell7 Then
SDRank = RegCell7
Else
If CVIPCell RegCell7 And CVIPCell
< RegCell8 Then
SDRank = RegCell8
Else
If CVIPCell RegCell8 And
CVIPCell < RegCell9 Then
SDRank = RegCell9
Else
If CVIPCell RegCell9 And
CVIPCell < RegCell10 Then
SDRank = RegCell10
Else
If CVIPCell RegCell10
And CVIPCell < RegCell11 Then
SDRank = RegCell11
Else
If CVIPCell
RegCell11 And CVIPCell < RegCell12 Then
SDRank = RegCell12
Else
SDRank = ""
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If

**************

Obviously, this is unfinished... it goes on for 12 inspection numbers
and is essentially used to shift a range around up or down 12 cells in
order to rank and return the closest equivalent value based on that
ranking in the dynamic range, with InspectionNumber determining the
range.

This formula returns everything that I want it to. The problem is the
formatting of the returned results. RegCellneg11 through RegCell12 are
the shifting range and refer to the same cells of the same datatype.
When this condition is met:

" If CVIPCell < RegCell1 And (RegCell1 - CVIPCell) <= 31 Then
SDRank = RegCell1
Else..."

(meaning that it returns the value of RegCell1) the format comes back
as date/time. However, whenever any other condition is met, the result
comes back as text! Now it is only possible for this to occur when
InspectionNumber = 1, and so I am only ever getting one instance of
date/time out of 12 times this occurs (InspectionNumbers 1 - 12)... I
only say this because I am dumping this data back into Access for
manipulation, Excel messing up the data formats means that Access can't
recognize the data.

If you've read this far and have any ideas on how to force RegCell1 to
return itself as text, please reply here! Thanks!:)
-Sean

 
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
A somewhat complex (to me at least) Nested IF issue The Narcissist Excel Worksheet Functions 0 January 23rd 08 12:07 AM
Creating a Complex What if in Excel: Beyond Nested Conditionals [email protected] Excel Programming 17 November 5th 06 12:20 AM
Complex Vlookup and List Validation and Nested IF statements Bobby Excel Worksheet Functions 2 March 9th 06 05:37 PM
Complex data referencing - too many for nested IF's djDaemon Excel Worksheet Functions 3 January 28th 06 12:04 AM
HELP? nested, complex, vlookup? The impossible! ricdik Excel Worksheet Functions 2 January 19th 06 05:08 AM


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