Hi, It is good to start programming from the starting point. In most of the programing languages you need to declare variables before writing the codes. In VBA (Excel Macros) 'Dim' is the keyword for declaration of the variables. It is good habit to declare variables in VBA if you want to be a good programmer.
So, the next question is, what is variable, and why do we need to declare. Let's say we have following code in the VBA macro. i=Range("A1") the above code means that the variable 'i' will hold the value of Cell A1 of the active-sheet. This will work even if you don't declare it. In simple programs you can do without declaration of variable. But as the programs become more complex, you will need it to save several problems and errors. If you write 'Option explicit' at the top of the macro, it will force you to declare every variables. You can write a simple program like below and check what happens. ----------------------------- Option explicit Sub chkVariable() i = Range("A1") msgbox i End sub ------------------------ If you run the above program you will get an error message. If you add the following line below the 'Sub chkVariable' statement, the error message will vanish. Dim i as integer ' declare i as integer So you will go to next step. What kinds of variables we have. Simplest ones are 1. String (to hold text) 2. Integer (to hold integer values upto 65535) 3. Long ( to hold integer values much higher) 4. Double (to hold decimal numbers) 5. Byte (to hold numbers 0 to 255) 6. Boolean (to hold true, false values) And there are many more variable types special to Excel, such as: Range, sheet, Cell etc. For example let us suppose you are writing a VBA macro and you are typing the following line 'Dim i as ' once you type 'as' and space bar you will see a lot of variable-types suggestion. With practice you can learn more about these variable types. Hope this will help you start learning. Akhilesh On Thu, Sep 4, 2008 at 2:16 PM, Arjunm1984 <[EMAIL PROTECTED]> wrote: > > Hi, > > I am new to creating Macros in Excel.. > Can someone please let me know how and what is Dim function while > creating Macro's ? > > Regards, > Arjun > > > > -- Akhilesh Kumar Karna --~--~---------~--~----~------------~-------~--~----~ Visit the blog to download Excel tutorials at http://www.excel-macros.blogspot.com To post to this group, send email to excel-macros@googlegroups.com For more options, visit this group at http://groups.google.com/group/excel-macros?hl=en Visit & Join Our Orkut Community at http://www.orkut.com/Community.aspx?cmm=22913620 Visit the blog to download Excel tutorials at http://www.excel-macros.blogspot.com To Learn VBA Macros Please visit http://www.vbamacros.blogspot.com To see the Daily Excel Tips, Go to: http://exceldailytip.blogspot.com -~----------~----~----~----~------~----~------~--~---