VBA Range Activate - Explained with Examples

VBA activate range macro code helps you to activate a range in an excel worksheet. You can use the Activate method of Range object to activate any range or one single cell in the worksheet. You can follow this tutorial to know – how to activate a range using VBA in Excel 2003,2007,2010,2013 or above.

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


VBA Activate Method Excel Range Object

Why we need to activate a Range using VBA?

When we are automating any tasks we can activate a range and perform different tasks with the active range. For example, we can format the background color, font color, font style, font size etc.

VBA Activate Range – Syntax

Here is the example syntax to activate a range using VBA.

Range(“YourRange”).Activate

Usage:The below excel macro will activate range D1.

Range(“D1”).Activate

Here, Activate is the method of Range object. Where D1 is the Range which we want to activate.

VBA Activate Range – Examples

Please see the below VBA codes to activate a Range.

Example 1:Activating one single cell.

The below macro can be used to activate a one single cell. It can be written in two ways. The first one is using Range object and the second statement is using cells object(Range is a collection of cells or one single cell).

Sub Activating_Single_Cell()
Range("A2").Activate
'or
Cells(2, 1).Activate
End Sub

In Range(“A2”).Activate statement ‘A2’ is the range which we are activating. Here, ‘A’ is the column name and ‘2’ is the row number.

In Cells(2, 1).Activate statement ‘2’ is the row number and ‘1’ is the column number.

Example 2:Activating Multiple cells.

The below macro can be used to activate multiple cells. You can mention the start range and end range separated with a colon. For example, To activate a range from A2 to C3, you can mention as Range(“A2:C3”).Activate. This will activate A2, A3,B2,B3,C2,C3 Cells.

Sub Activating_multiple_Cells()
Range("A2:C3").Activate
End Sub

Example 3: Activating Multiple cells using VBA

We can also use the Cells syntax to active multiple Cells. The below macro will activate the same range (A2:C3) whcih we discussed above using Cells and Range object.

Sub Activating_multiple_Cells()
Range(Cells(2, 1), Cells(3, 3)).Activate
End Sub

Here Cells(2, 1) refers to A2 and Cells(3, 3) refers to C3. and wee need to use comma (,) instead of colon (:).

VBA for Activating a Range – Instructions

Please follow the below step by step instructions to execute the above mentioned VBA macros or codes:

  1. Open an Excel Workbook
  2. Press Alt+F11 to Open VBA Editor
  3. Insert a Module from Insert Menu
  4. Copy the above code for activating a range and Paste in the code window(VBA Editor)
  5. Save the file as macro enabled workbook
  6. Press ‘F5’ to run it or Keep Pressing ‘F8’ to debug the code line by line.

Now, you can see the range A2:C3 is activated in the active worksheet.

Recent Posts:

Hide Developer Tab in Excel Ribbon

Hide Developer Tab in Excel Ribbon using from the Excel options. It helps to prevent users from opening the Excel VBA editor window. Hide Developer Tab in Excel Ribbon: Right click on any main menu

  • Excel UserForm show hide unload

Show or Hide|Unload a userform

Show or hide means to display or hide a Userform. We use Show and Hide methods to display or hide. Unload will be used when completes the task.

  • Column Number to Column Name

Column Number to Column Name

Column Number to Column Name is nothing but converting column number to Excel alphabetic character column name. Most of the time while automating many tasks using Excel VBA, it may be required.

  • Column Number to Column Name

Column Name to Column Number

Column Name to Column Number is nothing but converting Excel alphabetic character column name to column number. Most of the time while automating many tasks it may be required. Please find the following details about conversion of column name to column number. You can also say column string to column number. Or get alphabetic character to column number using Excel VBA.

LIMITED TIME OFFER

Leave A Comment


Related pages


microsoft vba excelhow to unlock cells in excel 2007multiple if statements vbavlookup with truevba array functionsusing trim in excelddl commands sqlexcel template project timelinevba cleanexcel 2013 unprotect workbookdynamic vlookupexcel checkboxeshow to delete odd rows in excelhow to use a pivot table excel 2010excel sumif formulaspeed up vbahow do you merge cells in excel 2013ms access vba run macrovba excel savecreate an excel macroexcel formula trimexcel macro tipsvba application in excelgantt chart template for wordproject status report template powerpointhow do i filter out duplicates in excelexcel remove workbook protectionsum if excelvba excel codingunhide column a in excel 2013setting up a pivot tableexcel range lookupms access vba export query to excelvba timevaluevba multiselect listboxexcel counting duplicatesexcel how to unhide alldelete duplicates in excelhow do i filter out duplicates in excelmultiple if scenarios in excelvba access tutorialoffset in vbaopen recordset vbamacro enabled workbooksql ddl dml dclloops in vbavba select workbookhow to use the lookup function in excel 2010excel auto sortvba output to text filevba write to excelmerge a cell in excelformula match excelexcel formula sum ifactivesheet listobjectsrange.find vbacreate folder vbaiserror function in accessexample of vlookupexcel vba filefilterfind duplicates in a column in excelms excel chart typesgetting rid of duplicates in excellinking cells in excelmicrosoft office project management templatesexcel vba sortexcel vba screenupdatingvbscript file handlingunprotect excel onlinehow to add a blank row in excelswot template excelcolor code in vbalookup function excelms access vba run macroexcel combo box in cellvba text boxvba excel combo box