SlideShare a Scribd company logo
1 of 5
Macros Basic elementary knowledge
1
Abhirampobbisetty
1. Coding Tip 1
Always key in your code in lower case letters. If the spelling is right, the necessary letters will be
capitalized. If no letter gets capitalized.... check your spelling.
Exercise1-1
Step 1: Open a new workbook in Excel and use the ALT/F11 keys to go to the visual basic editor.
Step 2: In the code window of any of the sheets copy/paste the following macro:
Sub protest()
activecel.cop
End Sub
Notice that there are no capital letters in activecel.cop because both words are misspelled.
Step 3: Add a second "l" to "activecell" and an "y" to "copy" and then click "Enter". The sentence
now reads: Activecell.Copy with a capital "A" and a capital "C" because both words are spelled
correctly.
You now understand that significant letters are capitalised in each correctly spelled VBA word
when you move away from the line.
Step 5: Close Excel without saving anything
Macros Basic elementary knowledge
2
Abhirampobbisetty
2. Managing VBA Coding Errors
The Visual Basic Editor will help you avoid errors in coding in many different ways. You will not
have to wait at the end to be told that there is something wrong with your macro.
SyntaxErrors
The VBE will also tell you that there is a syntax error in what you have just written by making the
font red and showing you a message box.
Exercise1
Step 1: Open a new workbook in Excel and use the ALT/F11 keys to go to the visual basic editor
(VBE).
Step 2: In the code window of any of the sheet copy/paste the following line of
code:Range(A1").Select and click "Enter".
You get the following message box telling you that you are missing a "list separator". Look for the
error before the segment highlighted in blue. We can deduce that VBA is talking about the
missing quotation mark.
Step 3: Click on the "OK" button.
Step 4: Add the missing quotation mark, use the mouse to move the cursor to the end of the
sentence and click "Enter". The font is black meaning that everything is correct.
Macros Basic elementary knowledge
3
Abhirampobbisetty
Exercise2
Step 1: In the code window that you have used for exercise 1 copy/paste the following line of
code:
Range("A1".Select and click "Enter".
You get the following message box telling you that you are missing a "list separator". Look for the
error before the segment highlighted in blue. We can deduce that VBE is talking about the
missing parenthesis. Both the quotation marks in the exercise above and the parenthesis in this
exercise are considered as "list separator" by the VBE.
Step 2: Click on the "OK" button.
Step 3: Add the missing parenthesis, use the mouse to move the cursor to the end of the
sentence and click "Enter". The font is black meaning that everything is correct.
Step 4: Close Excel without saving anything
ScreenUpdating (Application.ScreenUpdating)
When you do not want to see your screen follow the actions of your VBA procedure (macro), you
start and end your code with the following sentences:
Application.ScreenUpdating = False
Then at the end:
Application.ScreenUpdating = True
Macros Basic elementary knowledge
4
Abhirampobbisetty
For reference :
Step 1: ALT+F11
Step 2: Copy the following macro in the code window of any sheet. As you can read: starting in
cell A1 a value of "99" will be entered in the selected cell then the cursor will move one cell
down to enter "99", repeat the process until the row number of the selected cell is 3000 and
come back to cell A1.
Sub testLesson13b1()
Range("A1").Select
Do Until Selection.Row = 3000
Selection.Value = 99
Selection.Offset(1, 0).Select
Loop
Range("A1").Select
End Sub
Step 3: Run the macro from Excel as you did with the previous one.
Step 4: Remove all the "99" from the cells
Step 5: Copy the following macro in the code window of a new workbook and run it. Two lines of
code have been added to the previous macro to prevent all the steps of the action to be seen on
the screen.
Sub testLesson13b2()
Application.ScreenUpdating = False
Range("A1").Select
Do Until Selection.Row = 3000
Selection.Value = 99
Selection.Offset(1, 0).Select
Loop
Range("A1").Select
Macros Basic elementary knowledge
5
Abhirampobbisetty
Application.ScreenUpdating = True
End Sub
Step 6: Run the macro from Excel as you did with the previous one. You will see a blank sheet, no
movement whatsoever and then a sheet where cells A1 to A3000 are equal to "99".
Sometimes you or the users might want to see the action. Some other times you or the user do
not want to see the action. It is up to you to use the sentence or not.
You can even use the pair of sentences (as below) anywhere within a long macro to refresh the
screen at significant points in the process. With the pair of sentences you call for a refreshment
withApplication.ScreenUpdating = True and then interrupt the refreshment process until the
next refreshment with Application.ScreenUpdating = False. Before the end of the macro you will
use a finalApplication.ScreenUpdating = True.
The pair of refreshing sentences:
Application.ScreenUpdating = True
Application.ScreenUpdating = False
Step 7: Close the workbook without saving anything

More Related Content

What's hot

What's hot (19)

Using Microsoft Excel2 Calculations
Using Microsoft Excel2 CalculationsUsing Microsoft Excel2 Calculations
Using Microsoft Excel2 Calculations
 
Ex13 lesson02
Ex13 lesson02Ex13 lesson02
Ex13 lesson02
 
Formulae
FormulaeFormulae
Formulae
 
Grade 5 Computer
Grade 5 ComputerGrade 5 Computer
Grade 5 Computer
 
Grade 6 Computer
Grade 6 Computer Grade 6 Computer
Grade 6 Computer
 
Mail innovations
Mail innovationsMail innovations
Mail innovations
 
Excel
ExcelExcel
Excel
 
Sequence diagram
Sequence diagram Sequence diagram
Sequence diagram
 
Lesson9 Working With Basic Functions
Lesson9 Working With Basic FunctionsLesson9 Working With Basic Functions
Lesson9 Working With Basic Functions
 
Excel 2007 slide enter formulas
Excel 2007 slide    enter formulasExcel 2007 slide    enter formulas
Excel 2007 slide enter formulas
 
Assignment1 min function[1] powerpoint
Assignment1 min function[1] powerpointAssignment1 min function[1] powerpoint
Assignment1 min function[1] powerpoint
 
Ma3696 Lecture 1
Ma3696 Lecture 1Ma3696 Lecture 1
Ma3696 Lecture 1
 
E_Pick in TM1
E_Pick in TM1E_Pick in TM1
E_Pick in TM1
 
Excel.02
Excel.02Excel.02
Excel.02
 
Top 10 excel tips
Top 10 excel tipsTop 10 excel tips
Top 10 excel tips
 
Microsoft Excel 2013 Basics course
Microsoft Excel 2013 Basics courseMicrosoft Excel 2013 Basics course
Microsoft Excel 2013 Basics course
 
Advance MS Excel
Advance MS ExcelAdvance MS Excel
Advance MS Excel
 
Lesson9 working with basic functions
Lesson9 working with basic functionsLesson9 working with basic functions
Lesson9 working with basic functions
 
Acct120 Class #14 Microsoft Excel Features
Acct120   Class #14   Microsoft Excel FeaturesAcct120   Class #14   Microsoft Excel Features
Acct120 Class #14 Microsoft Excel Features
 

Viewers also liked

P1 presentación plan de viabilidad pop&mitas
P1 presentación plan de viabilidad   pop&mitasP1 presentación plan de viabilidad   pop&mitas
P1 presentación plan de viabilidad pop&mitasInes Sofia Ortiz
 
Vampire cinema
Vampire cinemaVampire cinema
Vampire cinemanerea-rp
 
Advocacy: Anti-bullying
Advocacy: Anti-bullyingAdvocacy: Anti-bullying
Advocacy: Anti-bullyingMandyZhou
 
Jessica May - Occupational identity
Jessica May - Occupational identity Jessica May - Occupational identity
Jessica May - Occupational identity Jess May
 
Grading visible learners nagel-slides visible learning institute san diego
Grading visible learners nagel-slides visible learning institute san diegoGrading visible learners nagel-slides visible learning institute san diego
Grading visible learners nagel-slides visible learning institute san diegoNags4444
 
Album arts analysed examples
Album arts analysed examplesAlbum arts analysed examples
Album arts analysed examplesmo_usman
 

Viewers also liked (13)

P1 presentación plan de viabilidad pop&mitas
P1 presentación plan de viabilidad   pop&mitasP1 presentación plan de viabilidad   pop&mitas
P1 presentación plan de viabilidad pop&mitas
 
Vampire cinema
Vampire cinemaVampire cinema
Vampire cinema
 
Advocacy: Anti-bullying
Advocacy: Anti-bullyingAdvocacy: Anti-bullying
Advocacy: Anti-bullying
 
Jessica May - Occupational identity
Jessica May - Occupational identity Jessica May - Occupational identity
Jessica May - Occupational identity
 
創業管理:兼職創業者完整課程 Week 2
創業管理:兼職創業者完整課程 Week 2創業管理:兼職創業者完整課程 Week 2
創業管理:兼職創業者完整課程 Week 2
 
Grading visible learners nagel-slides visible learning institute san diego
Grading visible learners nagel-slides visible learning institute san diegoGrading visible learners nagel-slides visible learning institute san diego
Grading visible learners nagel-slides visible learning institute san diego
 
1
11
1
 
創業管理:兼職創業者完整課程 week7
創業管理:兼職創業者完整課程 week7創業管理:兼職創業者完整課程 week7
創業管理:兼職創業者完整課程 week7
 
創業管理:兼職創業者完整課程 Week 4
創業管理:兼職創業者完整課程 Week 4創業管理:兼職創業者完整課程 Week 4
創業管理:兼職創業者完整課程 Week 4
 
Album arts analysed examples
Album arts analysed examplesAlbum arts analysed examples
Album arts analysed examples
 
Trabajo de animales de ingles
Trabajo de animales de inglesTrabajo de animales de ingles
Trabajo de animales de ingles
 
Java file
Java fileJava file
Java file
 
Wishclubteamusa_russia
Wishclubteamusa_russiaWishclubteamusa_russia
Wishclubteamusa_russia
 

Similar to Macros

การบ้านวิชาห้องสมุด
การบ้านวิชาห้องสมุดการบ้านวิชาห้องสมุด
การบ้านวิชาห้องสมุดbanpotza
 
Excel Tutorials - Deleting the Empty Rows
Excel Tutorials - Deleting the Empty Rows Excel Tutorials - Deleting the Empty Rows
Excel Tutorials - Deleting the Empty Rows Merve Nur Taş
 
Basic Functions - Excel 2013 Tutorial
Basic Functions - Excel 2013 TutorialBasic Functions - Excel 2013 Tutorial
Basic Functions - Excel 2013 TutorialSpreadsheetTrainer
 
Excel Formulas Functions
Excel Formulas FunctionsExcel Formulas Functions
Excel Formulas Functionssimply_coool
 
A Quick Simple MS Excel Macro
A Quick Simple MS Excel MacroA Quick Simple MS Excel Macro
A Quick Simple MS Excel MacroPranav Ghode
 
Excel Formulas Functions 2007
Excel Formulas Functions 2007Excel Formulas Functions 2007
Excel Formulas Functions 2007simply_coool
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1rupeshkanu
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vbarjg_vijay
 
Tutorials on Macro
Tutorials on MacroTutorials on Macro
Tutorials on MacroAnurag Deb
 
Ms excel 2007 tutorial
Ms excel 2007 tutorialMs excel 2007 tutorial
Ms excel 2007 tutorialjks2010
 
Mfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-stepMfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-stepnamtranvanpt
 
Forgot Password to Unprotect Excel Sheet in Two Cases
Forgot Password to Unprotect Excel Sheet in Two CasesForgot Password to Unprotect Excel Sheet in Two Cases
Forgot Password to Unprotect Excel Sheet in Two CasesAadewea
 
Excel VBA.pptx
Excel VBA.pptxExcel VBA.pptx
Excel VBA.pptxGiyaShefin
 
Succeeding in Business with Microsoft Excel 2010 A Problem Solving Approach 1...
Succeeding in Business with Microsoft Excel 2010 A Problem Solving Approach 1...Succeeding in Business with Microsoft Excel 2010 A Problem Solving Approach 1...
Succeeding in Business with Microsoft Excel 2010 A Problem Solving Approach 1...KeithRomeros
 

Similar to Macros (20)

Excel vba
Excel vbaExcel vba
Excel vba
 
การบ้านวิชาห้องสมุด
การบ้านวิชาห้องสมุดการบ้านวิชาห้องสมุด
การบ้านวิชาห้องสมุด
 
VISUAL
VISUALVISUAL
VISUAL
 
Excel Tutorials - Deleting the Empty Rows
Excel Tutorials - Deleting the Empty Rows Excel Tutorials - Deleting the Empty Rows
Excel Tutorials - Deleting the Empty Rows
 
Basic Functions - Excel 2013 Tutorial
Basic Functions - Excel 2013 TutorialBasic Functions - Excel 2013 Tutorial
Basic Functions - Excel 2013 Tutorial
 
Excel Formulas Functions
Excel Formulas FunctionsExcel Formulas Functions
Excel Formulas Functions
 
A Quick Simple MS Excel Macro
A Quick Simple MS Excel MacroA Quick Simple MS Excel Macro
A Quick Simple MS Excel Macro
 
Vba 2 (students copy)
Vba 2 (students copy)Vba 2 (students copy)
Vba 2 (students copy)
 
Excel Formulas Functions 2007
Excel Formulas Functions 2007Excel Formulas Functions 2007
Excel Formulas Functions 2007
 
Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1Excel Vba Basic Tutorial 1
Excel Vba Basic Tutorial 1
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
 
Tutorials on Macro
Tutorials on MacroTutorials on Macro
Tutorials on Macro
 
Ms excel 2007 tutorial
Ms excel 2007 tutorialMs excel 2007 tutorial
Ms excel 2007 tutorial
 
Mfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-stepMfc programming tutorial automation step by-step
Mfc programming tutorial automation step by-step
 
Forgot Password to Unprotect Excel Sheet in Two Cases
Forgot Password to Unprotect Excel Sheet in Two CasesForgot Password to Unprotect Excel Sheet in Two Cases
Forgot Password to Unprotect Excel Sheet in Two Cases
 
Microsoft excel part 1
Microsoft excel part 1Microsoft excel part 1
Microsoft excel part 1
 
Excel VBA.pptx
Excel VBA.pptxExcel VBA.pptx
Excel VBA.pptx
 
Vbabook ed2
Vbabook ed2Vbabook ed2
Vbabook ed2
 
18BCS5EL-U5 (1).pdf
18BCS5EL-U5 (1).pdf18BCS5EL-U5 (1).pdf
18BCS5EL-U5 (1).pdf
 
Succeeding in Business with Microsoft Excel 2010 A Problem Solving Approach 1...
Succeeding in Business with Microsoft Excel 2010 A Problem Solving Approach 1...Succeeding in Business with Microsoft Excel 2010 A Problem Solving Approach 1...
Succeeding in Business with Microsoft Excel 2010 A Problem Solving Approach 1...
 

Macros

  • 1. Macros Basic elementary knowledge 1 Abhirampobbisetty 1. Coding Tip 1 Always key in your code in lower case letters. If the spelling is right, the necessary letters will be capitalized. If no letter gets capitalized.... check your spelling. Exercise1-1 Step 1: Open a new workbook in Excel and use the ALT/F11 keys to go to the visual basic editor. Step 2: In the code window of any of the sheets copy/paste the following macro: Sub protest() activecel.cop End Sub Notice that there are no capital letters in activecel.cop because both words are misspelled. Step 3: Add a second "l" to "activecell" and an "y" to "copy" and then click "Enter". The sentence now reads: Activecell.Copy with a capital "A" and a capital "C" because both words are spelled correctly. You now understand that significant letters are capitalised in each correctly spelled VBA word when you move away from the line. Step 5: Close Excel without saving anything
  • 2. Macros Basic elementary knowledge 2 Abhirampobbisetty 2. Managing VBA Coding Errors The Visual Basic Editor will help you avoid errors in coding in many different ways. You will not have to wait at the end to be told that there is something wrong with your macro. SyntaxErrors The VBE will also tell you that there is a syntax error in what you have just written by making the font red and showing you a message box. Exercise1 Step 1: Open a new workbook in Excel and use the ALT/F11 keys to go to the visual basic editor (VBE). Step 2: In the code window of any of the sheet copy/paste the following line of code:Range(A1").Select and click "Enter". You get the following message box telling you that you are missing a "list separator". Look for the error before the segment highlighted in blue. We can deduce that VBA is talking about the missing quotation mark. Step 3: Click on the "OK" button. Step 4: Add the missing quotation mark, use the mouse to move the cursor to the end of the sentence and click "Enter". The font is black meaning that everything is correct.
  • 3. Macros Basic elementary knowledge 3 Abhirampobbisetty Exercise2 Step 1: In the code window that you have used for exercise 1 copy/paste the following line of code: Range("A1".Select and click "Enter". You get the following message box telling you that you are missing a "list separator". Look for the error before the segment highlighted in blue. We can deduce that VBE is talking about the missing parenthesis. Both the quotation marks in the exercise above and the parenthesis in this exercise are considered as "list separator" by the VBE. Step 2: Click on the "OK" button. Step 3: Add the missing parenthesis, use the mouse to move the cursor to the end of the sentence and click "Enter". The font is black meaning that everything is correct. Step 4: Close Excel without saving anything ScreenUpdating (Application.ScreenUpdating) When you do not want to see your screen follow the actions of your VBA procedure (macro), you start and end your code with the following sentences: Application.ScreenUpdating = False Then at the end: Application.ScreenUpdating = True
  • 4. Macros Basic elementary knowledge 4 Abhirampobbisetty For reference : Step 1: ALT+F11 Step 2: Copy the following macro in the code window of any sheet. As you can read: starting in cell A1 a value of "99" will be entered in the selected cell then the cursor will move one cell down to enter "99", repeat the process until the row number of the selected cell is 3000 and come back to cell A1. Sub testLesson13b1() Range("A1").Select Do Until Selection.Row = 3000 Selection.Value = 99 Selection.Offset(1, 0).Select Loop Range("A1").Select End Sub Step 3: Run the macro from Excel as you did with the previous one. Step 4: Remove all the "99" from the cells Step 5: Copy the following macro in the code window of a new workbook and run it. Two lines of code have been added to the previous macro to prevent all the steps of the action to be seen on the screen. Sub testLesson13b2() Application.ScreenUpdating = False Range("A1").Select Do Until Selection.Row = 3000 Selection.Value = 99 Selection.Offset(1, 0).Select Loop Range("A1").Select
  • 5. Macros Basic elementary knowledge 5 Abhirampobbisetty Application.ScreenUpdating = True End Sub Step 6: Run the macro from Excel as you did with the previous one. You will see a blank sheet, no movement whatsoever and then a sheet where cells A1 to A3000 are equal to "99". Sometimes you or the users might want to see the action. Some other times you or the user do not want to see the action. It is up to you to use the sentence or not. You can even use the pair of sentences (as below) anywhere within a long macro to refresh the screen at significant points in the process. With the pair of sentences you call for a refreshment withApplication.ScreenUpdating = True and then interrupt the refreshment process until the next refreshment with Application.ScreenUpdating = False. Before the end of the macro you will use a finalApplication.ScreenUpdating = True. The pair of refreshing sentences: Application.ScreenUpdating = True Application.ScreenUpdating = False Step 7: Close the workbook without saving anything