SlideShare a Scribd company logo
VBA Programming for Excel 
 Review Excel Objects 
 Excel Methods 
 Identifying Specific Cells 
 Review Functions for Excel 
 Custom Menus
Range Objects 
 Range(Name) 
 Name: text string 
 “B3”,”Input” 
 Offset 
 Range(“B3”).Offset(2,1) = Range(“C5”) 
 Offset numbers can be called 
MyNumber = 3 
Range(“D4”).Offset(myNumber, -1).Select 
<Results: Cursor ends up in cell C7>
Default Objects 
 ActiveCell 
 ActiveCell.Offset(0,1).Select 
 RowNum = ActiveCell.Row 
 ActiveSheet 
 ActiveSheet.Name = “Data” 
 ActiveSheet.Visible = VeryHidden 
 Selection 
 Selection.Clear
What does this code do? 
ActiveCell.Offset(Range(“B2”),-2) = [b4]/4 
4
Controlling Objects 
 Use assignment statements to change 
objects or properties 
 Different effects, similar results 
 Range(“F3”).Value = Range(“D3”).Value*15 
 Range (“F3”).Formula = “=D3*15” 
 First form enter a number – no updates! 
 Second form enters a formula
Collections 
 Worksheets 
 Worksheets(1) 
 Worksheets(“Sheet2”) 
 Columns 
Columns(“C:D”).HorizontalAlignment = xlCenter 
 Rows 
Rows(5).RowHeight = 19.5 
 Note difference between Row and 
Rows
Excel Methods 
 Record macros to define 
 Copy, Paste 
Range(“B3:D6”).Select 
Selection.Copy 
 Sort
Find a Given Cell 
 GoTo 
 Edit, Goto, Special 
 Last Cell 
 Current Region 
 {End}{Down} 
 Find first column in the last row
Look-ups 
 VLookUp(value, table, col_num, close) 
 Value: item to find 
 Table: range of data to search 
 Must be sorted by 1st column 
 Col_num: which column has data? 
 Close: true or false 
 True: select nearest match – always finds 
 False: find exact, or return #N/A
VLookUp 
Value to LookUp 
Search range 
Return column 
True: find 
closest match
Spreadsheet Functions in VBA 
 Application.WorkSheetFunction.Name(Arguments) 
Application.WorksheetFunction.Today() 
 Cell addresses must appear as ranges 
Application.WorkSheetFunction.IsNumber(Range(“B3”)) 
 Most worksheet functions have a VBA equivalent 
 Functions must be used in assignment statements 
vAns = Application.WorkSheetFunction. _ 
vLookup(Range(“A10”), Range(“A2:C8”), 3, True) 
vOut = Range(“A10”).formula & “ lives in “ vAns 
MsgBox vOut
Find() 
 VBA Function – not available on sheet 
 Expression.Find(What) 
 Expression must define a range on the 
spreadsheet 
 Returns Range location of first match 
 Expression range need not be sorted 
 If no match is found, it returns Nothing
Find( ) Function 
Range(“C10”).Value = _ 
Range(“A2:A8”).Find(“Gene”).Offset(0,2).Value 
Looks in cells A2:A8 for 
“Gene”, 
returns [A5] 
Offsets 2 cells right from [A5] 
returns [C5] 
Finds the value in [C5] = 58 
Puts the value 58 in [C10]
User Defined Functions 
 You can write your own custom functions 
 Decide what information will be passed in 
(Arguments) 
 Decide what value will be returned 
 Decide how VBA will use the arguments to 
calculate the returned value 
 Example: Determine employee bunuses 
 Argument: Amount of sales 
 Return value: Bonus amount 
 Bonus = 2% if Sales > $50,000
User-defined Functions 
 Form: Function Name(Arguments) 
 Unlike Sub – the name of the function 
must be repeated in the code 
Function Bonus(Sales) 
If Sales > 50000 Then 
Bonus = Sales * 0.02 
Else 
Bonus = 0 
End If 
End Function
Using Custom Functions 
 Functions can be called from another sub 
vSales = Range(“B3”).Value 
vBonus = Bonus(vSales) 
Range(“C3”).Value = vBonus 
 Functions can be used in the spreadsheet 
 Use Function Generator [fx] 
 Look under “User-defined” 
 Place cursor in [C3], write: 
=Bonus(B3) 
 Note how the results differ! 
 See VBAFunctions.xls in the handouts
Custom Menus 
 Define Variables 
 Use Set to define contents 
Dim myButton As CommandBarButton 
Set myButton = CommandBars("Worksheet Menu Bar")_ 
.Controls("Tools").Controls.Add 
With myButton 
.Caption = "Say Hi" 
.MoveBefore:=4 
.OnAction = "SayHi" 
.FaceId = 2174 
End With 
Caption: Words in menu list 
MoveBefore: Position in list 
OnAction: Macro to call 
FaceID: Icon to display
Removing Menu Items 
 Search the existing buttons 
 Remove identified items 
For Each Item In CommandBars("Worksheet Menu Bar")_ 
.Controls("Tools").Controls 
If Item.Caption = "Say Hi" Then 
Item.Delete 
Exit For 
End If 
Next Item
Activating Custom Menus 
 Menu code goes in a macro 
 Macro must be run to make menu 
appear or disappear 
 Use WorkBook_Open to add menues 
 Use WorkBook_BeforeClose to remove 
 See SayHi.xls in the handouts

More Related Content

What's hot

Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)harman kaur
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
DataminingTools Inc
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord models
Kostyantyn Stepanyuk
 
Writing Group Functions - DBMS
Writing Group Functions - DBMSWriting Group Functions - DBMS
Writing Group Functions - DBMS
Solaiman Hridoy
 
EAV Sytem- Magento EAV Model
EAV Sytem- Magento EAV ModelEAV Sytem- Magento EAV Model
EAV Sytem- Magento EAV Model
Khoa Truong Dinh
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
Ahmed Yaseen
 
Python Programming
Python Programming Python Programming
Python Programming
Sreedhar Chowdam
 
Nokia Asha App Development - Part 2
Nokia Asha App Development - Part 2Nokia Asha App Development - Part 2
Nokia Asha App Development - Part 2
Marlon Luz
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
Syed Zaid Irshad
 
Get more from excel
Get more from excelGet more from excel
Get more from excel
Gopal Sridharan
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
MugdhaSharma11
 
Sql functions
Sql functionsSql functions
Sql functions
G C Reddy Technologies
 
Excel formulas-manual
Excel formulas-manualExcel formulas-manual
Excel formulas-manualsrv1972
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)Tâm
 
Geometria analitica con geogebra secme 22589
Geometria analitica con geogebra secme 22589Geometria analitica con geogebra secme 22589
Geometria analitica con geogebra secme 22589
EmilioEscalanteHerna
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
Parthipan Parthi
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Achmad Solichin
 

What's hot (20)

Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord models
 
Writing Group Functions - DBMS
Writing Group Functions - DBMSWriting Group Functions - DBMS
Writing Group Functions - DBMS
 
EAV Sytem- Magento EAV Model
EAV Sytem- Magento EAV ModelEAV Sytem- Magento EAV Model
EAV Sytem- Magento EAV Model
 
Les06
Les06Les06
Les06
 
Introduction To Oracle Sql
Introduction To Oracle SqlIntroduction To Oracle Sql
Introduction To Oracle Sql
 
Python Programming
Python Programming Python Programming
Python Programming
 
Nokia Asha App Development - Part 2
Nokia Asha App Development - Part 2Nokia Asha App Development - Part 2
Nokia Asha App Development - Part 2
 
Using single row functions to customize output
Using single row functions to customize outputUsing single row functions to customize output
Using single row functions to customize output
 
Get more from excel
Get more from excelGet more from excel
Get more from excel
 
MSc COMPUTER APPLICATION
MSc COMPUTER APPLICATIONMSc COMPUTER APPLICATION
MSc COMPUTER APPLICATION
 
Sql functions
Sql functionsSql functions
Sql functions
 
Excel formulas-manual
Excel formulas-manualExcel formulas-manual
Excel formulas-manual
 
Les07
Les07Les07
Les07
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
 
Geometria analitica con geogebra secme 22589
Geometria analitica con geogebra secme 22589Geometria analitica con geogebra secme 22589
Geometria analitica con geogebra secme 22589
 
Practica dos
Practica dosPractica dos
Practica dos
 
Dbms lab questions
Dbms lab questionsDbms lab questions
Dbms lab questions
 
Les02 (restricting and sorting data)
Les02 (restricting and sorting data)Les02 (restricting and sorting data)
Les02 (restricting and sorting data)
 

Viewers also liked

Materi Pemfaktoran Persamaan Kuadrat
Materi Pemfaktoran Persamaan KuadratMateri Pemfaktoran Persamaan Kuadrat
Materi Pemfaktoran Persamaan Kuadrat
Indah Lestari
 
SOAL BILANGAN BULAT
SOAL BILANGAN BULATSOAL BILANGAN BULAT
SOAL BILANGAN BULAT
trisno direction
 
1. bab bilangan bulat
1. bab bilangan bulat1. bab bilangan bulat
1. bab bilangan bulat
Lea Febrina Bukit
 
Matematik Tambahan: Persamaan kuadratik
Matematik Tambahan: Persamaan kuadratikMatematik Tambahan: Persamaan kuadratik
Matematik Tambahan: Persamaan kuadratik
Cikgu Marzuqi
 
BAB I : Operasi Hitung Bilangan
BAB I : Operasi Hitung BilanganBAB I : Operasi Hitung Bilangan
BAB I : Operasi Hitung Bilangan
School of Visual Arts
 
PPT Puzzle Milus 1
PPT Puzzle Milus 1PPT Puzzle Milus 1
PPT Puzzle Milus 1
Indah Sari
 
Ppt kpk dan fpb.pptx vvvv
Ppt kpk dan fpb.pptx vvvvPpt kpk dan fpb.pptx vvvv
Ppt kpk dan fpb.pptx vvvvRela Tusriyanto
 
Dokumen.tips kelas 7-matematika-bab-1-bilangan-bulat (2)
Dokumen.tips kelas 7-matematika-bab-1-bilangan-bulat (2)Dokumen.tips kelas 7-matematika-bab-1-bilangan-bulat (2)
Dokumen.tips kelas 7-matematika-bab-1-bilangan-bulat (2)
Antoni Antoni
 
Bahan Ajar Bilangan Bulat
Bahan Ajar Bilangan BulatBahan Ajar Bilangan Bulat
Bahan Ajar Bilangan Bulat
Dara-71
 
Operasi hitung bilangan bulat
Operasi hitung bilangan bulatOperasi hitung bilangan bulat
Operasi hitung bilangan bulat
walsihlestari_wolly
 
Soal mtk
Soal mtkSoal mtk
Soal mtk
Hendra Saragih
 
Soal UTS TIK kelas 7 semester 2 hardware
Soal UTS TIK kelas 7 semester 2 hardwareSoal UTS TIK kelas 7 semester 2 hardware
Soal UTS TIK kelas 7 semester 2 hardware
Citra Aero
 
SOAL UAS GANJIL MATEMATIKA SMP KELAS VII 2015/2016
SOAL UAS GANJIL MATEMATIKA SMP KELAS VII 2015/2016SOAL UAS GANJIL MATEMATIKA SMP KELAS VII 2015/2016
SOAL UAS GANJIL MATEMATIKA SMP KELAS VII 2015/2016
Budi Haryono
 
Soal unas &amp; pembahasan
Soal unas  &amp; pembahasanSoal unas  &amp; pembahasan
Soal unas &amp; pembahasan
Annisa Rahmaw
 

Viewers also liked (14)

Materi Pemfaktoran Persamaan Kuadrat
Materi Pemfaktoran Persamaan KuadratMateri Pemfaktoran Persamaan Kuadrat
Materi Pemfaktoran Persamaan Kuadrat
 
SOAL BILANGAN BULAT
SOAL BILANGAN BULATSOAL BILANGAN BULAT
SOAL BILANGAN BULAT
 
1. bab bilangan bulat
1. bab bilangan bulat1. bab bilangan bulat
1. bab bilangan bulat
 
Matematik Tambahan: Persamaan kuadratik
Matematik Tambahan: Persamaan kuadratikMatematik Tambahan: Persamaan kuadratik
Matematik Tambahan: Persamaan kuadratik
 
BAB I : Operasi Hitung Bilangan
BAB I : Operasi Hitung BilanganBAB I : Operasi Hitung Bilangan
BAB I : Operasi Hitung Bilangan
 
PPT Puzzle Milus 1
PPT Puzzle Milus 1PPT Puzzle Milus 1
PPT Puzzle Milus 1
 
Ppt kpk dan fpb.pptx vvvv
Ppt kpk dan fpb.pptx vvvvPpt kpk dan fpb.pptx vvvv
Ppt kpk dan fpb.pptx vvvv
 
Dokumen.tips kelas 7-matematika-bab-1-bilangan-bulat (2)
Dokumen.tips kelas 7-matematika-bab-1-bilangan-bulat (2)Dokumen.tips kelas 7-matematika-bab-1-bilangan-bulat (2)
Dokumen.tips kelas 7-matematika-bab-1-bilangan-bulat (2)
 
Bahan Ajar Bilangan Bulat
Bahan Ajar Bilangan BulatBahan Ajar Bilangan Bulat
Bahan Ajar Bilangan Bulat
 
Operasi hitung bilangan bulat
Operasi hitung bilangan bulatOperasi hitung bilangan bulat
Operasi hitung bilangan bulat
 
Soal mtk
Soal mtkSoal mtk
Soal mtk
 
Soal UTS TIK kelas 7 semester 2 hardware
Soal UTS TIK kelas 7 semester 2 hardwareSoal UTS TIK kelas 7 semester 2 hardware
Soal UTS TIK kelas 7 semester 2 hardware
 
SOAL UAS GANJIL MATEMATIKA SMP KELAS VII 2015/2016
SOAL UAS GANJIL MATEMATIKA SMP KELAS VII 2015/2016SOAL UAS GANJIL MATEMATIKA SMP KELAS VII 2015/2016
SOAL UAS GANJIL MATEMATIKA SMP KELAS VII 2015/2016
 
Soal unas &amp; pembahasan
Soal unas  &amp; pembahasanSoal unas  &amp; pembahasan
Soal unas &amp; pembahasan
 

Similar to Excell vba

belajar VBA
belajar VBAbelajar VBA
belajar VBA
Hendi Alfiandi
 
Working with shapes
Working with shapesWorking with shapes
Introduction to DAX Language
Introduction to DAX LanguageIntroduction to DAX Language
Introduction to DAX Language
Antonios Chatzipavlis
 
Excel 2007 Unit H
Excel 2007 Unit HExcel 2007 Unit H
Excel 2007 Unit H
Raja Waseem Akhtar
 
OBIEE 12c Advanced Analytic Functions
OBIEE 12c Advanced Analytic FunctionsOBIEE 12c Advanced Analytic Functions
OBIEE 12c Advanced Analytic FunctionsMichael Perhats
 
Ms excel
Ms excelMs excel
1.2 Zep Excel.pptx
1.2 Zep Excel.pptx1.2 Zep Excel.pptx
1.2 Zep Excel.pptx
PizzaM
 
Excel Macros and VBA Demo.docx
Excel Macros and VBA Demo.docxExcel Macros and VBA Demo.docx
Excel Macros and VBA Demo.docx
gunjangupta861854
 
Excel Macros and VBA Demo.docx
Excel Macros and VBA Demo.docxExcel Macros and VBA Demo.docx
Excel Macros and VBA Demo.docx
gunjangupta861854
 
Python Lecture 4
Python Lecture 4Python Lecture 4
Python Lecture 4
Inzamam Baig
 
Tutorials on Macro
Tutorials on MacroTutorials on Macro
Tutorials on Macro
Anurag Deb
 
9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx
SheryldeVilla2
 
Mdx Basics
Mdx BasicsMdx Basics
Mdx BasicsALIPPHAR
 
What are Tableau Functions? Edureka
What are Tableau Functions? EdurekaWhat are Tableau Functions? Edureka
What are Tableau Functions? Edureka
Edureka!
 
6 Function Built In (Excel 2019 dn 365).pptx
6 Function Built In (Excel 2019 dn 365).pptx6 Function Built In (Excel 2019 dn 365).pptx
6 Function Built In (Excel 2019 dn 365).pptx
PuworkUtara OnSlideshare
 
Excel functions, formulas, Prepared by singh institute RK Puram
Excel functions, formulas, Prepared by singh institute RK PuramExcel functions, formulas, Prepared by singh institute RK Puram
Excel functions, formulas, Prepared by singh institute RK Puram
Simranjit Singh Chopra
 
C# excel bar chart
C# excel bar chartC# excel bar chart
C# excel bar chartChen Stephen
 

Similar to Excell vba (20)

belajar VBA
belajar VBAbelajar VBA
belajar VBA
 
Working with shapes
Working with shapesWorking with shapes
Working with shapes
 
Introduction to DAX Language
Introduction to DAX LanguageIntroduction to DAX Language
Introduction to DAX Language
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
Excel 2007 Unit H
Excel 2007 Unit HExcel 2007 Unit H
Excel 2007 Unit H
 
OBIEE 12c Advanced Analytic Functions
OBIEE 12c Advanced Analytic FunctionsOBIEE 12c Advanced Analytic Functions
OBIEE 12c Advanced Analytic Functions
 
Ms excel
Ms excelMs excel
Ms excel
 
1.2 Zep Excel.pptx
1.2 Zep Excel.pptx1.2 Zep Excel.pptx
1.2 Zep Excel.pptx
 
Excel.useful fns
Excel.useful fnsExcel.useful fns
Excel.useful fns
 
Excel Macros and VBA Demo.docx
Excel Macros and VBA Demo.docxExcel Macros and VBA Demo.docx
Excel Macros and VBA Demo.docx
 
Excel Macros and VBA Demo.docx
Excel Macros and VBA Demo.docxExcel Macros and VBA Demo.docx
Excel Macros and VBA Demo.docx
 
Python Lecture 4
Python Lecture 4Python Lecture 4
Python Lecture 4
 
Tutorials on Macro
Tutorials on MacroTutorials on Macro
Tutorials on Macro
 
9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx9 - Advanced Functions in MS Excel.pptx
9 - Advanced Functions in MS Excel.pptx
 
Mdx Basics
Mdx BasicsMdx Basics
Mdx Basics
 
What are Tableau Functions? Edureka
What are Tableau Functions? EdurekaWhat are Tableau Functions? Edureka
What are Tableau Functions? Edureka
 
6 Function Built In (Excel 2019 dn 365).pptx
6 Function Built In (Excel 2019 dn 365).pptx6 Function Built In (Excel 2019 dn 365).pptx
6 Function Built In (Excel 2019 dn 365).pptx
 
Excel functions, formulas, Prepared by singh institute RK Puram
Excel functions, formulas, Prepared by singh institute RK PuramExcel functions, formulas, Prepared by singh institute RK Puram
Excel functions, formulas, Prepared by singh institute RK Puram
 
C# excel bar chart
C# excel bar chartC# excel bar chart
C# excel bar chart
 
Project advance itt
Project advance ittProject advance itt
Project advance itt
 

Recently uploaded

678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 

Recently uploaded (20)

678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 

Excell vba

  • 1. VBA Programming for Excel  Review Excel Objects  Excel Methods  Identifying Specific Cells  Review Functions for Excel  Custom Menus
  • 2. Range Objects  Range(Name)  Name: text string  “B3”,”Input”  Offset  Range(“B3”).Offset(2,1) = Range(“C5”)  Offset numbers can be called MyNumber = 3 Range(“D4”).Offset(myNumber, -1).Select <Results: Cursor ends up in cell C7>
  • 3. Default Objects  ActiveCell  ActiveCell.Offset(0,1).Select  RowNum = ActiveCell.Row  ActiveSheet  ActiveSheet.Name = “Data”  ActiveSheet.Visible = VeryHidden  Selection  Selection.Clear
  • 4. What does this code do? ActiveCell.Offset(Range(“B2”),-2) = [b4]/4 4
  • 5. Controlling Objects  Use assignment statements to change objects or properties  Different effects, similar results  Range(“F3”).Value = Range(“D3”).Value*15  Range (“F3”).Formula = “=D3*15”  First form enter a number – no updates!  Second form enters a formula
  • 6. Collections  Worksheets  Worksheets(1)  Worksheets(“Sheet2”)  Columns Columns(“C:D”).HorizontalAlignment = xlCenter  Rows Rows(5).RowHeight = 19.5  Note difference between Row and Rows
  • 7. Excel Methods  Record macros to define  Copy, Paste Range(“B3:D6”).Select Selection.Copy  Sort
  • 8. Find a Given Cell  GoTo  Edit, Goto, Special  Last Cell  Current Region  {End}{Down}  Find first column in the last row
  • 9. Look-ups  VLookUp(value, table, col_num, close)  Value: item to find  Table: range of data to search  Must be sorted by 1st column  Col_num: which column has data?  Close: true or false  True: select nearest match – always finds  False: find exact, or return #N/A
  • 10. VLookUp Value to LookUp Search range Return column True: find closest match
  • 11. Spreadsheet Functions in VBA  Application.WorkSheetFunction.Name(Arguments) Application.WorksheetFunction.Today()  Cell addresses must appear as ranges Application.WorkSheetFunction.IsNumber(Range(“B3”))  Most worksheet functions have a VBA equivalent  Functions must be used in assignment statements vAns = Application.WorkSheetFunction. _ vLookup(Range(“A10”), Range(“A2:C8”), 3, True) vOut = Range(“A10”).formula & “ lives in “ vAns MsgBox vOut
  • 12. Find()  VBA Function – not available on sheet  Expression.Find(What)  Expression must define a range on the spreadsheet  Returns Range location of first match  Expression range need not be sorted  If no match is found, it returns Nothing
  • 13. Find( ) Function Range(“C10”).Value = _ Range(“A2:A8”).Find(“Gene”).Offset(0,2).Value Looks in cells A2:A8 for “Gene”, returns [A5] Offsets 2 cells right from [A5] returns [C5] Finds the value in [C5] = 58 Puts the value 58 in [C10]
  • 14. User Defined Functions  You can write your own custom functions  Decide what information will be passed in (Arguments)  Decide what value will be returned  Decide how VBA will use the arguments to calculate the returned value  Example: Determine employee bunuses  Argument: Amount of sales  Return value: Bonus amount  Bonus = 2% if Sales > $50,000
  • 15. User-defined Functions  Form: Function Name(Arguments)  Unlike Sub – the name of the function must be repeated in the code Function Bonus(Sales) If Sales > 50000 Then Bonus = Sales * 0.02 Else Bonus = 0 End If End Function
  • 16. Using Custom Functions  Functions can be called from another sub vSales = Range(“B3”).Value vBonus = Bonus(vSales) Range(“C3”).Value = vBonus  Functions can be used in the spreadsheet  Use Function Generator [fx]  Look under “User-defined”  Place cursor in [C3], write: =Bonus(B3)  Note how the results differ!  See VBAFunctions.xls in the handouts
  • 17. Custom Menus  Define Variables  Use Set to define contents Dim myButton As CommandBarButton Set myButton = CommandBars("Worksheet Menu Bar")_ .Controls("Tools").Controls.Add With myButton .Caption = "Say Hi" .MoveBefore:=4 .OnAction = "SayHi" .FaceId = 2174 End With Caption: Words in menu list MoveBefore: Position in list OnAction: Macro to call FaceID: Icon to display
  • 18. Removing Menu Items  Search the existing buttons  Remove identified items For Each Item In CommandBars("Worksheet Menu Bar")_ .Controls("Tools").Controls If Item.Caption = "Say Hi" Then Item.Delete Exit For End If Next Item
  • 19. Activating Custom Menus  Menu code goes in a macro  Macro must be run to make menu appear or disappear  Use WorkBook_Open to add menues  Use WorkBook_BeforeClose to remove  See SayHi.xls in the handouts