Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Excel VBA - Lesson 1 - Basics


Published on

Published in: Education
  • Be the first to comment

Excel VBA - Lesson 1 - Basics

  1. 1. Lesson 1
  2. 2. We all imagine that doing Programming inExcel, is to add new things to Excel and so itis some thing not easy to learn.Interestingly programming Excel is not reallyabout adding new features as much as it isabout combining existing features to solvespecific problems.
  3. 3. Programming in Excel is to make some task easierand more reliable.Through Programming, you are asking Excel to docertain tasks and Excel Follows that.Programming languages make things easierbecause they are great at performing repetitiveoperations and following a logical path withoutgetting tired or bored. They make things morereliable because they follow your directions andnever, ever get creative.
  4. 4. The best way to learn Macros and break theice is by recording code.Thru this you can learn about Excel objects,properties, and methods. We will discuss thesame in detail, in coming slides. When we record a macro, we can see that, itis rather writing a code on its own ( a visualbasic code)
  5. 5. Let us record a macro with a regular activity Which we repeatedly use on our daily routine. For Example, with a particular Data, I wanted to change the format and convert that into a Graph. Choose Tools - > Macros -> Record New Macro A dialog box appears as shown here ( Record Macro)Select Data Format Option Select Format
  6. 6. Select Data Insert Charts Simple Graph Appears While Recording Macro, “Record Macro” Button, becomes a small Blue Square. Once your Recording is over, you need to stop recording as shown below
  7. 7. The task described in earlier slide ,was recorded in thebelow Macro Sub Macro1() macro_1 Macro Range("A2:B6").Select ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$2:$B$6"), , xlYes).Name = _ "Table2" Range("Table2[#All]").Select ActiveSheet.ListObjects("Table2").TableStyle = "TableStyleMedium2" ActiveSheet.Shapes.AddChart.Select ActiveChart.SetSourceData Source:=Range("Sheet1!$A$2:$B$6") ActiveChart.ChartType = xlColumnClustered End Sub
  8. 8. In the next Lesson –1. Reading and Understanding Recorded Code2. Macros and Security3. Classes , Modules and Procedures