VBA MID Function
அன்றாட எக்செல் வாழ்க்கையில், முதல், கடைசி அல்லது நடுத்தர சப்ஸ்ட்ரைங்கை மீட்டெடுக்க வேண்டிய பல நிகழ்வுகள் உள்ளன.இந்த சூழ்நிலைகளில், நம் தேவைகளைப் பூர்த்தி செய்ய உரை சூத்திரங்களை நம்பலாம்.
What is MID Function?
The VBA MID Function is commonly used to extract the values (usually a substring) from the middle from a full-text string. It is categorized under String type variable.
VBA மிட் செயல்பாட்டின் பயனர் முழு உரை சரத்தின் நடுத்தர பகுதியை மீட்டெடுக்க முடியும்.விபிஏ சர செயல்பாடுகள் அசல் சரத்தைப் பாதுகாக்கின்றன என்பது அவர்களின் சிறந்த அம்சங்களில் ஒன்றாகும்.அதற்கு பதிலாக, அவர்கள் எக்செல் பணித்தாள் செயல்பாடு மற்றும் விபிஏ செயல்பாடு இரண்டையும் இந்த செயல்பாடு மூலம் பயன்படுத்தலாம்.இது செல்லின் சூத்திரத்தில் இணைக்கப்படலாம். VBA செயல்பாடுகளின் உரை வகை MID function ஐ உள்ளடக்கியது.
Syntax
MID(string variable, starting point, [length])
OR
MID(text_string, start_number, char_numbers)
OR
Mid(string_to_search, starting position, number_of_characters)
Parameter
String or text_string or string_to_search (required): நாங்கள் பிரித்தெடுக்க விரும்பும் சரத்தின் நீளம் சர அளவுருவால் குறிக்கப்படுகிறது.
Starting point or start_number (required): துணை சர பிரித்தெடுத்தலுக்கான தொடக்க எழுத்து இந்த வாதத்தால் குறிக்கப்படுகிறது.
Length or number-of_characters (optional): தொடக்க இடத்திலிருந்து நீங்கள் எத்தனை எழுத்துக்களைப் பெற விரும்புகிறீர்கள் என்பது மட்டுமே இந்த நீள விருப்பத்தால் குறிக்கப்படுகிறது.
Return
The VBA MID Function is commonly used to extract the values (usually a substring) from the middle from a full-text string.
Points to Remember
- The VBA MID function returns a string-based output for a given string.
- IF the specified string argument is Null, this function will return Null as the output.
- In this function, if the parameter start_number is greater than the length of the text_string argument, the VBA MID function returns an empty string (zero-length) as an output.
Examples
# MID Function Example 1: Fetch the middle name from the string “Sukla Rani Panda”.
உள்ளமைக்கப்பட்ட செயல்பாடுகளில் ஒன்றான VBA MID, ஒரு சரத்தின் ஒரு பகுதியை (பொதுவாக நடுத்தர சப்ஸ்ட்ரிங்) அல்லது பயனர் வழங்கிய மதிப்பை மட்டுமே மீட்டெடுக்க பயனர்களால் அடிக்கடி பயன்படுத்தப்படுகிறது. ஒரு VBA ஐ உருவாக்குவதற்கான வழிமுறைகள்.
Step 1: Open the VBA developer tab. Go to Excel worksheet, from the ribbon tab click on developer window -> visual basic editor or directly click on the shortcut keywords Alt +F11.
Step 2: The VB Editor window will be displayed. The next step is to create a module. From the ribbon tab click on Insert-> Click on Module.

Step 3: You will notice, VBA will insert a new module window. Start the program by introduce your macro name followed by the declaration of the variable.
Refer to the below given macro code:
- Sub MID_Function _Example1()
- ‘Declaring the string variable
- Dim MidNme As String
- End Sub
Store the fetch value in our variable and later return the variable using MsgBox.
- Sub MID_Function_Example1()
- ‘Declaring the string variable
- Dim MidNme As String
- ‘Using the Mid function to extract the middle name
- MidMidNme = Mid(“Sukla Rani Panda”, 6, 5)
- ‘returning the output
- MsgBox MidNme
- End Sub

Output
Run your macro either by clicking Run or by pressing the F5 key. As a result, you will notice VBA will throw a MsgBox displaying middle string.

#MID Example 2: Fetch the middle name from the list of Excel cells using VBA MID Function.
VBA மொழியின் பல வழிகளில் எழுதும் திறன் ஒரு பிளஸ்.நிகழ்வைக் கிளிக் செய்யும்போதெல்லாம் Active பொத்தான் VBA MID மேக்ரோவை இயக்கும்.நீங்கள் உடனடியாக T ஐ பிரித்தெடுக்கலாம்.
Step 1: Open the Excel worksheet. From the ribbon tab click on developer window -> visual basic editor or directly click on the shortcut keywords Alt +F11.
Step 2: The VB Editor window will be displayed. The next step is to create a module. From the ribbon tab click on Insert-> Click on Module.

Step 3: The Moule window will be inserted. Start the program with the macro name followed by the declaration of the variable. Set the variable value with the Excel selection.
Refer to the following macro code:
- Sub MID_Function_Example2()
- ‘Declare the variable
- Dim i As Long
- End Sub
- Sub MID_Function_Example2()
- ‘Declare the variable
- Dim i As Long
- ‘For loop to iterate the formula for each cell
- For i = 3 To 11
- ‘using MID function to extract the middle values
- Cells(i, 2).Value = Mid(Cells(i, 1).Value, 1, InStr(1, Cells(i, 1).Value, “,”) – 1)
- Next i
- End Sub
Once we are done with code writing, we will close the VBA editor window. Again, go to your Excel worksheet click on the Developer -> Insert menu.

சுட்டியைப் பயன்படுத்தி உங்கள் Excel பணித்தாளில் எங்கும் பொத்தான் படிவத்தை வரையவும்.முன்னர் உருவாக்கப்பட்ட மேக்ரோக்களின் பட்டியலிலிருந்து தேர்ந்தெடுப்பதைத் தவிர, மேக்ரோவுக்கு ஒரு பெயரைக் கொடுங்கள்.MID Function Example2 ஐ தேர்ந்தெடுத்துள்ளோம்.

எனவே உங்கள் எக்செல் விரிதாளில் விரும்பிய இடத்தில் பொத்தான் உருவாக்கப்படும்.பெயரின் மேலே இருமுறை கிளிக் செய்தால் அதை திருத்தவும் முடியும்.நாங்கள் இப்போது MID செயல்பாட்டை கொண்டு வந்துள்ளோம்.

இறுதி படி இந்த பொத்தானை ஒரு மேக்ரோவுடன் இணைப்பதாகும்.MID பொத்தானை வலது கிளிக் செய்யவும். கிடைக்கக்கூடிய மேக்ரோக்கள் தோன்றும் சாளரத்தில் காண்பிக்கப்படும்.”MI” என்ற பெயருடன் மார்கோவைத் தேர்ந்தெடுத்த பிறகு சரி என்பதைக் கிளிக் செய்க.
Output
We will insert some text strings in various cells to test the above macro.

For testing, select the cells with data and then click on the MID Button.

As a result, you will notice all the middle names has been extracted from the list of cells.
# MID Function Example 3: VBA MID program returns an empty string.
பகுத்தறிவின் முழு சங்கிலியும் நன்றாக இருக்கும்போது கூட, நீங்கள் எப்போதாவது வெற்று சரத்தைப் பெறலாம்.இந்த வகை பிழைக்கு தொடக்க எண் அளவுரு உரை சர வாதத்தின் நீளத்தை தாண்டக்கூடாது.
Step 1: Open the VBA developer tab. Go to Excel worksheet, from the ribbon tab click on developer window -> visual basic editor or directly click on the shortcut keywords Alt +F11.
Step 2: The VB Editor window will be displayed. The next step is to create a module. From the ribbon tab click on Insert-> Click on Module.

Step 3: You will notice, VBA will insert a new module window. Start the program by introduce your macro name followed by the declaration of the variable.
Refer to the below given macro code:
- Sub MID_Function _Example3()
- ‘Declaring the string variable
- Dim MidNme As String
- End Sub
Step 4: Next, we will incorporate the VBA MID function. In the arguments, we will pass the String, the start_character i.e., 26 and in the length argument, we will pass 15. As you will notice, the start_character is nore than the actual string.
Store the fetch value in our variable and later return the variable using MsgBox.
- Sub MID_Function_Example3()
- ‘Declaring the string variable
- Dim MidNme As String
- ‘Using the Mid function to extract the middle name
- MidMidNme = Mid(“Sukla Rani Panda”, 26, 15)
- ‘returning the output
- MsgBox MidNme
- End Sub

Output
இயக்கு என்பதைக் கிளிக் செய்யவும் அல்லது உங்கள் மேக்ரோவைத் தொடங்க F5 விசையைப் பயன்படுத்தவும்.இதன் விளைவாக, VBA நடுத்தர சரத்தைக் கொண்ட ஒரு Msg Box காண்பிக்கப்படும்.
