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


excel vba clear cellexcel vba dynamic arraysimple excel gantt chart templateunhide excel columnsql beginnersvlookup in excel 2003call worksheet function from vbaadvanced excel shortcuts pdfexcel useful macrosexcel activecellexcel timeline templatescosting spreadsheet templatedeveloping macros in excelprotecting an excel spreadsheetsql interview questions for business analystvba upper boundsimple gantt chart template excel 2010vba macro excel examplesexcel if statement rangeexcel duplicate cellproject schedule excel templatelink sql to excelexcel formula in vbaexcel consolidate functionexcel unhide commandhow to sort excel sheets alphabeticallyvba row hidevba activate workbookjob estimate template wordproject management timeline templatehow to edit hyperlink in excelsave excel file vbatrend analysis excel templatehow to unprotect excellookup function in excel 2007combobox vba codeslicer in excel 2010 tutorialcell address vbaadvanced filter vbavba macro codevba in excel 2007 tutorialexcel macro input boxhow to delete repeated rows in excelmacros in sqlmacro excel programmingexcel graph filterexcel 2007 dashboard examplesvba read cellremove blank lines exceldocmd.opentablesorting in sqlproject charter template wordhow unprotect excel sheetwhile loop in excelexcel vba windowexcel offset vlookupvba excel learnexcel vba macroscode for comboboxhow to convert column to row in excelvba to export access query to excelvbyesno msgboxexcel checklist templatesfind duplicate entry in excelinteger function excelexcel quick tutorialvba dialog boxadvanced pivot table tutorialhow to unhide cells in excelthisworkbook vbacopy and paste excel sheethow to unprotect excel cellshlookupaverage function in excel 2013nested if functions excel 2010