?
Solved

Transfer ceiling function of excel to Access

Posted on 2004-11-09
13
Medium Priority
?
2,321 Views
Last Modified: 2012-06-27
Hi

I have a function in an Excel spreadsheet that takes a value from a field, adds 3%, rounds that value up to a multiple of 5 while ensuring that it is divisible by 24.

It is =(CEILING((C34*1.03)/24,5))*24

does anyone know how to replicate this over to an Access query
0
Comment
Question by:jainesteer
  • 3
  • 3
  • 2
  • +4
13 Comments
 
LVL 16

Expert Comment

by:Nestorio
ID: 12540846
Try,

=(Int((C34*1.03)/24,5) + 1)*24
0
 

Author Comment

by:jainesteer
ID: 12540891
That gives an error of "function contains the wrong number of arguments"
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 12540998
Say [MyValue] contains the original number you had in C34,

NewValue:(Int([MyValue]/24)*5))*24

or

NewValue:(Int([MyValue]/24)*5)+1)*24    ' I am not sure about +1

Mike
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 26

Expert Comment

by:Alan Warren
ID: 12541004
Hi jainesteer


There is no roundup or rounddown function in Access, I wrote one that can be called in SQL if you want it, let me know.

If you use the backslash integer divisor it will always return an integer, truncating the decimal part.

Think this is mathematically correct,
but as soon as you round it up to the nearest 5 no guarantee it will be divisible by 24 anymore
(((((12345*1.03)\24)*24)+5)\5)*5

returns: 12700

To round down dont add 5
((((12345*1.03)\24)*24)\5)*5

Returns: 12695

 


Alan
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 12541014
Igno my post... I leave it up to real experts (Alan and  Nestorio)

Mike
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12541029
Mike, what the...?

I've learnt many a neat trick from you mate.


Alan
0
 
LVL 34

Expert Comment

by:flavo
ID: 12541053
my 2cs.

I just let excel to what it does best

Function myCeiling(lNumber, lSignificance) As Double
'Needs a refrence to Microsoft Excel Object Library ?.?
'To do this, in VBA window, Tools - Refrences and tick it from the list
myCeiling = Excel.WorksheetFunction.CEILING(lNumber, lSignificance)

End Function

Sub testIt()

MsgBox myCeiling(0.5, 1)

End Sub
0
 

Author Comment

by:jainesteer
ID: 12541212
Alan:  I need to be sure so I don't think I will go with your suggestion - but thanks for the effort

Mike:  I did not seem to get the right answer

Flavo:  It is more than I wanted to do with the problem but I suppose at least I know that it will work.   Which leads me to the question, how to make it work.  I was wanting to run a macro from Access that effectively ran a query and dropped the result into excel.  If the query is designed to create a new excel spreadsheet, do you have any idea how I could populate this field directly from the macro?
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12541499
jainesteer: what do you need to be sure of?
0
 
LVL 9

Expert Comment

by:Bat17
ID: 12541776
Why not just recreate the ceiling function as a custom function and use that?

Function pCeiling(dblValue As Double, dblSig As Double) As Double
If Int(dblValue / dblSig) <> dblValue / dblSig Then
    pCeiling = Int(dblValue / dblSig) * dblSig + dblSig
Else
    pCeiling = dblValue
End If
End Function

This will work OK but does not check that the signs are the same.

=(pCeiling((C34*1.03)/24,5))*24


HTH

Peter
0
 
LVL 58

Accepted Solution

by:
harfang earned 500 total points
ID: 12541998
Back to Excel:
   =(CEILING((C34*1.03)/24,5))*24

If you do not have CEILING, use INT, thus
   = CEILING( C34, 5 )
is almost the same as
   = ( INT( C34 / 5 ) + 1 ) * 5
but it fails for 5... so you have to remove a small value, as in
   = ( INT( C34 / 5 - 0.00000001 ) + 1 ) * 5

In the original statement, you combine the CEILING and the INT method...
Let's use INT (leaving the .0000001 out for the time being):
   = (CEILING((C34*1.03)/24,5))*24
   = ( ( INT( (C24*1.03)/24 / 5) +1 ) * 5 ) * 24

But that looks very much like:
   =  ( INT( (C34*1.03)/120 ) +1 ) *120

So this is your expression, Access compatible, too :)

You will have to decide whether you need the - 0.000001 :)
That's the hard part of a Ceiling function, actually...

Looking a bit closer the true equivalent of Ceiling(value) is something like:
   Int(Value) - ( ( Value - Int(Value ) > 0 )       ' Assuming True = -1
Or: take the integer portion and add 1 if there is a decimal portion...

But do you really want (in Excel, TRUE = 1):
   = ( INT(C34*1.03/120) + ( ( (C34*1.03/120)-INT(C34*1.03/120) ) > 0 ) ) * 120
only for a *true* ceiling workaround???

Good Luck :)
0
 
LVL 58

Expert Comment

by:harfang
ID: 12542027
> " If the query is designed to create a new excel spreadsheet, do you have any idea how I could populate this field directly from the macro?"
Sometimes, depending on the method used for the transfer, you can write functions into Excel. If the query has something like:
    FunctionXL: "= CEILING( RC[-1] * 103%, 120)"
This would create a function taking the next multiple of 120 for 103% of the cell in the previous column...

Good Luck!
0
 

Author Comment

by:jainesteer
ID: 12551061
Thanks everyone - all for something that I thought should be so straightforward.  I will go with Harfang with the  =  ( INT( (C34*1.03)/120 ) +1 ) *120
I have put this into the sql and all works well.  From there I will just pull the field into Excel as I do with all of the others in that query.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question