VBA code to check if active cell is blank

Home/VBA/VBA code to check if active cell is blank

VBA to check if an active cell is blank macro will help us to determine whether an active range is filled with some value or not. This example will help us to know how to check if an active cell or a range is blank or not using Excel VBA. This can be used in Excel 2003,2007,2010,2013.

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 code to check if an active cell is blank – Syntax

Here is the example Excel VBA Syntax to check if an active cell is blank or not. The below macro will check whether an active Range is blank or not.

If ActiveCellctiveCell = "" Then
... Statements to execute if the Cell is Empty 
Else
...statements to execute if Cell is not Blank.
end if

VBA code to check if an activecell is blank – Example

Here is the example macro to check if an ActiveCell cell is blank or not. The below macro will show a message box based on active Cell value.

Sub vba_code_to_check_if_active_cell_is_blank()
If ActiveCell = "" Then
MsgBox "ActiveCell is Blank"
Else
MsgBox "ActiveCell is not blank"
End If
End Sub

VBA code to check if an ActiveCell is blank – Better Example: Avoid Empty Spaces

Sometimes, A cell or rang looks blank and we notice that the condition is failing. It is mostly because of the empty spaces in the cell. So, whenever you want to check if an active cell is empty, you can trim the ActiveCell value and check it.

Sub vba_code_to_check_if_active_cell_is_blank() 
'use trim to avoide blank spaces
If Trim(ActiveCell) = "" Then
MsgBox "ActiveCell is Blank"
Else
MsgBox "ActiveCell is not blank"
End If
End Sub

VBA code to check if an Active Cell is blank – Instructions

Please follow the below step by step instructions to test this Example VBA Macro codes:

  • Step 1: Open a New Excel workbook
  • Step 2: Press Alt+F11 – This will open the VBA Editor (alternatively, you can open it from Developer Tab in Excel Ribbon)
  • Step 3: Insert a code module from then insert menu of the VBE
  • Step 4: Copy the above code and paste in the code module which have inserted in the above step
  • Step 5: Enter some sample data at active cell and do not change the selection to check if the cell is blank or not using VBA.
  • Step 6: Now press F5 to execute the code or F8 to debug the Macro to check the if Range A1 is blank or not
LIMITED TIME OFFER
By |January 20th, 2015|VBA|1 Comment

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).

One Comment

  1. PRAKASH June 7, 2017 at 7:56 PM - Reply

    owsome efforts

Leave A Comment


Related pages


record macros in excelvb rangeexcel formula codesmicrosoft excel macroshow to unhide sheets in excelremove duplicate from excelsql basic questions and answerscreate project timeline in excelexcel 2003 lookupexcel conditional statementapplication filedialog msofiledialogfilepickerddl language in sqlexcel password lockexcel vba rowvba valuemacro coding in excelexcel vba refresh all pivot tableshow to unhide hidden columns in exceltutorial vba excelcharttitlevba collection excellookup functions in excelexcel template project trackerexcel hyperlink to macroexcel macro commandshow to combine sheets in excelvba create databaseconcatenate on excelvlookup samplevba count worksheetsadodb connection string sql servervlookup examples in excelrgb excel vbaunprotect powerpointopen excel file using vbahow to learn excel vbahow to delete sheets in excelsql query to connect to databasevba excel macro tutorialhow to use the average function in excel 2013how to use the sumif functionadvanced excel macrounhide all cellsvba excel save workbookvba sheet namesumif in excelsql programmer interview questionsexcel pivot tables advancedcreate macros excelisna function excelcountif excel examplevba excel tablelookup excel exampleexcel hide sheetshow to use nested if function in excel 2010excel select empty rowsclear cells vbaisblank in excelvba excel chartsxls macro tutorialcheckbox syntaxif isnumeric vbafind duplicates in excel 2007excel 2007 chart wizardexcel vba write to access databasewhat is col index num in vlookupmacros programming in excelvba rangesexcel dynamic cell referenceunhide column a in excel 2013vba open a filerisk dashboard template excelexcel hyperlink functionaccess vba in excelexcel shortcut insert rowmsgbox vba excelaverage function excel 2010rename files using excelhr interview questions with answers for freshers pdfproject timeline template excel 2007excel charts samplescreate excel drop down list 2007dbms for dummies