Syntax – VBA Instr Function

Home/VBA Instr Function/Syntax – VBA Instr Function

VBA Instr will help us to find a position of a specific character in a string and get the required part from the main sting. Here is the Syntax of the VBA Instr Function. We use Instr function mainly get the sub string from a main string.



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

Syntax of VBA Instr Function

We can find the potion of a sub string in the main string using VBA Instr Function. We need to specify position to start find, main sting, sub string.

Below is the Syntax of VBA Instr Function:

InStr([Start], [String1], [String2], [Compare As])

Parameters of VBA Instr Function

Start: Position to Start Finding the Sub String in the Main String.
String1: Main String to Search the Sub String.
String2: Sub Sting to Search in the Main String.

VBA Instr Function – Simple Example

The below Example finds the position of a sub sting (How) in the Main String (Hello! How Are You?).

Sub sbVBAInstrFunction_SimpeExample()
'Syntax; InStr([Start], [String1], [String2], [CompareAs])
strMain = "Hello! How Are You?"
strSub = "How"
MsgBox InStr(1, strMain, strSub)
'Result: 8 (As you can see 'How' starts at position 8 in the Main String)
End Sub

Related pages

vbscript msgbox examplesexcel vba application.getsaveasfilenamepassword protect excel macroclose workbook without savinginsert function vbacapacity planning excel templateprogrammer interview sqlit business analyst interview questions and answers pdfmeeting minutes excel templateunlock workbook excelactive x definitionvba vlookup codededuplication excelindirect function in vbavbinformation vbadefine vlookupvba conditionsexcel how to change rows to columnsprotect cells excel 2007vba file system objectvba macro outlookprotecting excel filesoffset meaning in hindiunlock excel spreadsheet without passwordtesting questions for freshersvba workbookcapacity planning excel templateprogram excel macrosadd developer tab to the ribbon in wordbasic excel tests for interviewsms access adodb connectionexcel how to unhide column ahow to write macros in wordmacros in excel sheetvlookup formula excelarray in vba excelhide macros in excelvba excel stringexcel vba data typesexcel hidden worksheetvba outlook applicationvba as rangevba offset functionvba activeworksheetexcel vlookup tutorialwhere is chart wizard in excelexcel unlock password protected sheetdelete all blank rows in excelselection in excel vbaexcel advanced formulas examples excel sheetproject management excel gantt chart templateminute meetings templatevba save filefind duplicate row in excelexcel tutorial examplessample vbscript codeexcel vba xmlunload userformexcel template for timelineexcel vba color cellunhide first row in exceldbms interview questions and answers for freshers pdfexcel macro for vlookupsql ddl dml dcl tcl commands pdfexcel project management dashboard templatemacro security excel 2010open file vba accessexcel vba insert multiple rowsunprotect sheet excelexcel macro remove blank rowsunprotect sheet excel 2007excel duplicate recordshow to unlock protected cells in excelarray in excel vbacountif formula in excel 2007vba do loopsexcel vba end of columnautofit column width excelmatch vbacolor cells in excelvba sql query excel