Objects in Excel VBA – Workbook, Sheets, Range and Cell

Home/Excel VBA/Objects in Excel VBA – Workbook, Sheets, Range and Cell

We have seen different Objects in the previous tutorial, we will see the different examples on Workbook, Sheets, Range and Cell objects in this session.
Objects in Excel VBA - Workbook, Sheets, Range and Cell

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


Workbook Object in Excel VBA

The following are some example codes on Workbook Object, will help you dealing with various methods and properties of Excel workbook.

How to activate a Workbook

Yo can use Activate method to activate a Workbook as shown below:

Workbooks(“Workbook1.xlsx”).Activate

How to get the path of the Workbook

Yo can use FullName method of a Workbook as shown below:

Workbooks(“Workbook1.xlsx”).Path

How to get the full path (including name) of the Workbook

Yo can use FullName method of a Workbook as shown below:

Workbooks(“Workbook1.xlsx”).FullName

How to change the name of the Workbook

Workbooks(“Workbook1″).Name=”New Name”

Worksheet Object of Workbook in Excel VBA

The following are some example codes on Worksheet Object, will help you to deal with activating and selecting Excel worksheet.

How to Activate a Worksheet

Sheets(“Sheet2”).Activate

How to Select a Worksheet

Sheets(“Sheet2”).Select

How to rename a Worksheet

Sheets(“Sheet2″).Name=”NewSheet”

How to Hide a Worksheet

Sheets(“Sheet2”)..Visible = False

How to UnHide a Worksheet

Sheets(“Sheet2”).Visible = True

Range Object of Worksheet in Excel VBA

The following are some example codes on Range Object, will help you to deal with range colors, selection, etc.

How to Select a Range

Range(“A3”).Select

How to Enter Some Data in a Range

Range(“A3”).value=3000

How to change background color of Range

Range(“A1:E20”).Interior.ColorIndex=5

How to Clear a Range

Range(“A1:E20”).Clear

How to Copy a Range from one sheet to another sheet

Sheets(“Sheet1”).Range(“A1:E20”).Copy Destination:=Sheets(“Sheet2”).Range(“D1”)

Cells Object of Worksheet in Excel VBA

The following are some example codes on Cells Object.

How to Select a Range(“A3”)

Cells(3,1).Select

How to Enter Some Data in a Range(“A3”)

Cells(3,1).value=3000

How to change Font color of a Cell

Cells(3,1).Font.ColorIndex=5

How to Clear all Cells of a worksheet

Sheets(“Sheet1”).Cells.Clear

How to Clear only content not formats of all Cells of a worksheet

Sheets(“Sheet1”).Cells.ClearContents

LIMITED TIME OFFER
By |July 6th, 2013|Excel VBA|0 Comments

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

Leave A Comment


Related pages


autosave excel 2010sql dml querieshow to unprotect an excel spreadsheetsql tutorial for experiencedexcel vba cut and paste rangemacro writing tutorialhow to do a pivot table in excel 2013vbscript msgbox examplesvba insurancevba code to save excel filemake a drop down list in excel 2007autofilter excel 2013select case in vbacoding worksheetsvba activate cellexcel vba colour indexvlookup functions in excel 2010trim formula excelmacro functions in excelexcel activeworkbookddl and dml commands in sql pdfdistinct rows in excelvba delete duplicateshow to adjust all column width in excelvba in excel tutorialexcel vba menudelete empty cellsexcel metrics dashboardunlock vba project passwordcase sensitive vlookupinterview questions and answers in c programming language pdfimplementation plan template excelhow do you unhide columns in excel 2010vba excel offsethow to create pivot tables in excel 2007how to delete blank rows in excel 2010excel 2010 combo boxexcel tutorial charts and graphsunlock excel spreadsheet without passwordvba selection.findmacro to insert rows in excelexcel tutorial torrentms access 2007 vba programming tutorial pdfexcel macro close without savingcut paste worksheetsdefine vbaproject charter template powerpointuseful vba functionsvba textbox propertiesvba excel close filevba excel copy sheetexcel vba do while loop examplefilesystemobject opentextfileexcel paste special transposecountif excel exampleexcel macro workbooks openvba hello worldcool excel macro tricksvba select case examplefso file existsvba paste valueunlock excel workbookvlookups in excel 2010tos codesvba worksheet rangecreating pivot charts in excel 2010useful macros for excelvba call subaccess 2007 vba tutorialexcel advanced filter wildcardvba rsmerge tabs in excelsubstitute function excelcool excel macrosexcel combine tables from multiple sheets