Re: $$Excel-Macros$$ payback Period Formula / Macro

2013-07-08 Thread Dominic Rassool
Hi David,

Im just getting to grips with VB; could you please let me know what Dim 
means? Thanks.

Best


On Saturday, 11 August 2012 15:56:32 UTC+4, David Grugeon wrote:
>
> Hi Sharad
>
> Use the following function in a general module.  Then use =Payback(range)  
>
> See attached
>
> '=
> Function PayBack(ByRef rng As Range) As Variant
> 'check that the range has only one dimension
> If rng.Rows.Count > 1 And rng.Columns.Count > 1 Then
> PayBack = "error"
> Else
>
> Dim t As Double 'The total value
> Dim t1 As Double
> Dim t2 As Double
> Dim x As Long 'cell counter
> Dim p As Double 'the part of the following year
>
> ' find the period
> Do Until t > 1
> x = x + 1
> t = t + rng.Cells(x).Value
> Loop
>
> PayBack = x - (t / rng.Cells(x).Value)
> End If
>
> End Function
> '=
>
> Regards
> David Grugeon
>
>
>  

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/groups/opt_out.




Re: $$Excel-Macros$$ payback Period Formula / Macro

2013-07-08 Thread Prince
HI 

*Hope this Will makes some sens for you.*

The word Dim is short for dimmension and is used to declare variables. Now, 
while Excel can still work quite happily if we omit the Dim (as long as we 
do not have Option Explicit), it comes at a price. Excel MUST store all 
undeclared variables as a Variant, meaning it can accept any data type 
(String, Iteger, Range etc). This forces Excel to reserve much more memory 
than really needed. So this is why 'good' code has all variables 
dimmensioned correctly.

There are 3 basic levels of Dim Statements.

1. Procedure Level
2. Module Level
3. Project Level

1. Procedure Level
Must be used inside of a Procedure between 

Sub MacroName()
Dim iInt as Integer

End Sub

This will ONLY retain the value passed to it while the Procedure is 
running, it is then destoyed.


2. Module Level
Must be placed at the very top of a Module and will then be available to 
ALL Procedures within that module.


3.Project Level
Must be placed at the very top of a Standard Module using the Public Key 
word, eg


Public iInt as Integer

This is then available to ALL Procedures in all modules at ALL times. Until 
we either:

1.Destroy the variable (set it back to it's default), eg iInt=0

2. Use the End statement in any Procedure.

3. Close the Workbook.

regards
Prince
On Monday, July 8, 2013 12:45:36 PM UTC+5:30, Dominic Rassool wrote:
>
> Hi David,
>
> Im just getting to grips with VB; could you please let me know what Dim 
> means? Thanks.
>
> Best
>
>
> On Saturday, 11 August 2012 15:56:32 UTC+4, David Grugeon wrote:
>>
>> Hi Sharad
>>
>> Use the following function in a general module.  Then use =Payback(range) 
>>  
>>
>> See attached
>>
>> '=
>> Function PayBack(ByRef rng As Range) As Variant
>> 'check that the range has only one dimension
>> If rng.Rows.Count > 1 And rng.Columns.Count > 1 Then
>> PayBack = "error"
>> Else
>>
>> Dim t As Double 'The total value
>> Dim t1 As Double
>> Dim t2 As Double
>> Dim x As Long 'cell counter
>> Dim p As Double 'the part of the following year
>>
>> ' find the period
>> Do Until t > 1
>> x = x + 1
>> t = t + rng.Cells(x).Value
>> Loop
>>
>> PayBack = x - (t / rng.Cells(x).Value)
>> End If
>>
>> End Function
>> '=
>>
>> Regards
>> David Grugeon
>>
>>
>>  

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/groups/opt_out.




Re: $$Excel-Macros$$ payback Period Formula / Macro

2013-09-24 Thread Gilberto Genga
Hello David,
I am working on XL2003, and tried inserting the function in a general 
module, but I continue to receive the "#NAME?" error when applying the 
formula...
Any quick hint?
Thanks in advance
 
Gilberto

On Saturday, 11 August 2012 12:56:32 UTC+1, David Grugeon wrote:

> Hi Sharad
>
> Use the following function in a general module.  Then use =Payback(range)  
>
> See attached
>
> '=
> Function PayBack(ByRef rng As Range) As Variant
> 'check that the range has only one dimension
> If rng.Rows.Count > 1 And rng.Columns.Count > 1 Then
> PayBack = "error"
> Else
>
> Dim t As Double 'The total value
> Dim t1 As Double
> Dim t2 As Double
> Dim x As Long 'cell counter
> Dim p As Double 'the part of the following year
>
> ' find the period
> Do Until t > 1
> x = x + 1
> t = t + rng.Cells(x).Value
> Loop
>
> PayBack = x - (t / rng.Cells(x).Value)
> End If
>
> End Function
> '=
>
> Regards
> David Grugeon
>
>
>  

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/groups/opt_out.


Re: $$Excel-Macros$$ payback Period Formula / Macro

2012-08-10 Thread RAJA SEKAR
Hi Sharad,

can u explain in brief??, Unable to get what exactly you want

On 10 August 2012 11:32, sharad jain  wrote:

> Hi,
>
> I need a formula or macro for calculating payback period which is dynamic.
> I mean that it can calculate the payback period for series of data without
> changing the formula itself again again.
>
> I am attaching an example sheet with 3 scenarios where we can have same
> formula / macro.
>
> Will appreciate any type of help here.
>
> Thanks,
> Sharad
>
> --
> Join official facebook page of this forum @
> https://www.facebook.com/discussexcel
>
> FORUM RULES (1120+ members already BANNED for violation)
>
> 1) Use concise, accurate thread titles. Poor thread titles, like Please
> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
> will not get quick attention or may not be answered.
>
> 2) Don't post a question in the thread of another member.
>
> 3) Don't post questions regarding breaking or bypassing any security
> measure.
>
> 4) Acknowledge the responses you receive, good or bad.
>
> 5) Cross-promotion of, or links to, forums competitive to this forum in
> signatures are prohibited.
>
> 6) Jobs posting is not allowed.
>
> 7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
>
> NOTE : Don't ever post personal or confidential data in a workbook. Forum
> owners and members are not responsible for any loss.
> ---
> You received this message because you are subscribed to the Google Groups
> "MS EXCEL AND VBA MACROS" group.
> To post to this group, send email to excel-macros@googlegroups.com.
> To unsubscribe from this group, send email to
> excel-macros+unsubscr...@googlegroups.com.
>
>
>



-- 
"Making a million friends is not a miracle, the miracle is to make a friend
who will stand by you when a million are against you. "





Have a Smileness Day
With A Smile
Rs.

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.




Re: $$Excel-Macros$$ payback Period Formula / Macro

2012-08-10 Thread Sj
Hi Shekar,

Payback is basically a financial tool to see how much it takes to recover 
your invest, in other words break even.

If I invest Rs. 100 in one project which gives me following returns - 1 
year Rs. 30, 2 year Rs. 40, 3 year  Rs. 60. We can see that I recover my 
investment / break even in somewhere in 3 year. We can assume that Rs. 60 
occur evenly throughout the year and we come to payback period of 2.5 years

For more on this topic, you can simply do a google search.

There is no in-build function for this in Excel. 

Regards,
Sharad 

On Friday, August 10, 2012 2:13:04 PM UTC+5:30, shekar wrote:
>
> Hi Sharad,
>
> can u explain in brief??, Unable to get what exactly you want
>
> On 10 August 2012 11:32, sharad jain >wrote:
>
>> Hi,
>>
>> I need a formula or macro for calculating payback period which is 
>> dynamic. I mean that it can calculate the payback period for series of data 
>> without changing the formula itself again again.
>>
>> I am attaching an example sheet with 3 scenarios where we can have same 
>> formula / macro.
>>
>> Will appreciate any type of help here.
>>
>> Thanks,
>> Sharad
>>
>> -- 
>> Join official facebook page of this forum @ 
>> https://www.facebook.com/discussexcel
>>  
>> FORUM RULES (1120+ members already BANNED for violation)
>>  
>> 1) Use concise, accurate thread titles. Poor thread titles, like Please 
>> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice 
>> will not get quick attention or may not be answered.
>>  
>> 2) Don't post a question in the thread of another member.
>>  
>> 3) Don't post questions regarding breaking or bypassing any security 
>> measure.
>>  
>> 4) Acknowledge the responses you receive, good or bad.
>>  
>> 5) Cross-promotion of, or links to, forums competitive to this forum in 
>> signatures are prohibited. 
>>  
>> 6) Jobs posting is not allowed.
>>  
>> 7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.
>>  
>> NOTE : Don't ever post personal or confidential data in a workbook. Forum 
>> owners and members are not responsible for any loss.
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "MS EXCEL AND VBA MACROS" group.
>> To post to this group, send email to excel-...@googlegroups.com
>> .
>> To unsubscribe from this group, send email to 
>> excel-macros...@googlegroups.com .
>>  
>>  
>>
>
>
>
> -- 
> "Making a million friends is not a miracle, the miracle is to make a 
> friend who will stand by you when a million are against you. " 
>
>
>
> 
>
>
> Have a Smileness Day
> With A Smile
> Rs.
>
>
>  

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.




Re: $$Excel-Macros$$ payback Period Formula / Macro

2012-08-11 Thread David Grugeon
Hi Sharad

Use the following function in a general module.  Then use =Payback(range)

See attached

'=
Function PayBack(ByRef rng As Range) As Variant
'check that the range has only one dimension
If rng.Rows.Count > 1 And rng.Columns.Count > 1 Then
PayBack = "error"
Else

Dim t As Double 'The total value
Dim t1 As Double
Dim t2 As Double
Dim x As Long 'cell counter
Dim p As Double 'the part of the following year

' find the period
Do Until t > 1
x = x + 1
t = t + rng.Cells(x).Value
Loop

PayBack = x - (t / rng.Cells(x).Value)
End If

End Function
'=

Regards
David Grugeon

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.




Example.xlsm
Description: Binary data


Re: $$Excel-Macros$$ payback Period Formula / Macro

2012-08-14 Thread Sj
Hi David,

Though it is working my main sheet. It is giving wrong results.

Can you please recheck? I have attached my actual numbers.

Thanks,
Sharad

On Saturday, August 11, 2012 5:26:32 PM UTC+5:30, David Grugeon wrote:
>
> Hi Sharad
>
> Use the following function in a general module.  Then use =Payback(range)  
>
> See attached
>
> '=
> Function PayBack(ByRef rng As Range) As Variant
> 'check that the range has only one dimension
> If rng.Rows.Count > 1 And rng.Columns.Count > 1 Then
> PayBack = "error"
> Else
>
> Dim t As Double 'The total value
> Dim t1 As Double
> Dim t2 As Double
> Dim x As Long 'cell counter
> Dim p As Double 'the part of the following year
>
> ' find the period
> Do Until t > 1
> x = x + 1
> t = t + rng.Cells(x).Value
> Loop
>
> PayBack = x - (t / rng.Cells(x).Value)
> End If
>
> End Function
> '=
>
> Regards
> David Grugeon
>
>
>  

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.




Example_v1.xlsm
Description: application/vnd.ms-excel.sheet.macroenabled.12


Re: $$Excel-Macros$$ payback Period Formula / Macro

2012-08-14 Thread sharad jain
Hi David,

Thanks a lot for your help on this. Really appreciate.

Best Regards,
Sharad

On Tue, Aug 14, 2012 at 3:19 PM, David Grugeon  wrote:

> Sorry.  I worked it for each input value being the cash flow for a year.
>  I see that you have put down a "Year 0" and the cash flows for the Year 0
> and Year 1 would both be in what I call Year 1.
>
> I have changed the macro to work in the way you do.
>
> PFA
>
>
> On 14 August 2012 17:04, Sj  wrote:
>
>> Hi David,
>>
>> Though it is working my main sheet. It is giving wrong results.
>>
>> Can you please recheck? I have attached my actual numbers.
>>
>> Thanks,
>> Sharad
>>
>>
>> On Saturday, August 11, 2012 5:26:32 PM UTC+5:30, David Grugeon wrote:
>>>
>>> Hi Sharad
>>>
>>> Use the following function in a general module.  Then use
>>> =Payback(range)
>>>
>>> See attached
>>>
>>> '=**
>>> Function PayBack(ByRef rng As Range) As Variant
>>> 'check that the range has only one dimension
>>> If rng.Rows.Count > 1 And rng.Columns.Count > 1 Then
>>> PayBack = "error"
>>> Else
>>>
>>> Dim t As Double 'The total value
>>> Dim t1 As Double
>>> Dim t2 As Double
>>> Dim x As Long 'cell counter
>>> Dim p As Double 'the part of the following year
>>>
>>> ' find the period
>>> Do Until t > 1
>>> x = x + 1
>>> t = t + rng.Cells(x).Value
>>> Loop
>>>
>>> PayBack = x - (t / rng.Cells(x).Value)
>>> End If
>>>
>>> End Function
>>> '=**
>>>
>>> Regards
>>> David Grugeon
>>>
>>>
>>>
>
>
> --
> Regards
> David Grugeon
>

-- 
Join official facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES (1120+ members already BANNED for violation)

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.

2) Don't post a question in the thread of another member.

3) Don't post questions regarding breaking or bypassing any security measure.

4) Acknowledge the responses you receive, good or bad.

5)  Cross-promotion of, or links to, forums competitive to this forum in 
signatures are prohibited. 

6) Jobs posting is not allowed.

7) Sharing copyrighted ebooks/pirated ebooks/their links is not allowed.

NOTE  : Don't ever post personal or confidential data in a workbook. Forum 
owners and members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To post to this group, send email to excel-macros@googlegroups.com.
To unsubscribe from this group, send email to 
excel-macros+unsubscr...@googlegroups.com.