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.