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.

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


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
LIMITED TIME OFFER

Related pages


public variables vbagoto vbavlookup meaning in excelhow to enable macro in excelexcel what if statementspyramid powerpoint templatevba excel getopenfilenamecount if excel formulaunprotect excel 2010 without passwordhow to insert multiple columns in excelautomatically refresh pivot tablevbokcancel vbavba excel replacewhat is ddl and dml in sql servertrend analysis excel templatewhile loop in excel macroexcel how to identify duplicatesvba if statementdelete duplicate rows in excelinsert text box excelvlookup with exampleexcel vba if statementsappend in excelsql interview questions in pdfadvance filter in excelinteractive excel dashboardbasics of vbavba range cells valueautofilter excel 2007excel vba validationduplicate records in excelexcel tables tutorialvba isblankbusiness analyst tutorial pdftrim function in excel 2007highlight duplicate excelremove duplicate values in excelmerge two columns in excelvba array uboundexcel vba formula in cellexcel macro write to text filedelete macros in excelhow to add extra rows in excelhow to write macros in wordexcel vba copy sheet to endexcel vba internet explorerms access iserrorunhide sheet excelvba changemacro to delete columnsvba tutorialcombine multiple excel files into one worksheetdata validation excel 2010automatically hide rows in excelsql query for beginnersmsgbox vbokvlookup formulasvba connection string to access databaseconstruction estimate excel templatecreate an array vbahow to merge cells with data in excelif statement examples in excelvba formattingvba worksheets rangeexcel run macrogantt chart sample excelexcel macro hyperlinkusing hlookupexcel vba report exampledynamic chart title excel 2010qlikview delete rowsvba workbooks.openunhide a sheet in excelcheck mark in excel 2007set password for excel 2007access vba query