VBA TRIM Function
Excel என்பது தரவைக் கையாள்வது மற்றும் மாற்றியமைப்பது பற்றியது. பொதுவாக, இந்த தரவு இணைய சேவையகங்கள் அல்லது பிற தரவுத்தள ஆதாரங்கள் வழியாக இறக்குமதி செய்யப்படுகிறது.ஒழுங்கமைக்கப்படாத தரவு மற்றும் கலத்தில் கூடுதல் இடங்கள் ஒரு பொதுவான பிரச்சினையாகும்.
What is VBA TRIM Function?
The VBA TRIM function is used to clean the unwanted spaces from your data. It will eliminate all the extra spaces from the characters of your string.
இந்த செயல்பாடு எளிதானது மற்றும் ஒரு சரத்தை ஒரு உள்ளீடாக எடுத்துக்கொள்கிறது, அது வெட்டப்பட வேண்டும்.சரத்தை எடுத்துக் கொள்ளுங்கள் “ஹலோ, நீங்கள் இந்த டுடோரியலை ரசிக்கிறீர்கள் என்று நம்புகிறீர்களா?”ஒரு உதாரணம். இங்கே, தேவையில்லாத முன்னணிகள் உள்ளன.
Leading Space: செல்லில் எந்த மதிப்பும் தொடங்குவதற்கு முன்பு உள்ள இடைவெளிகள் "முன்னணி இடம்" (ஏதேனும் இருந்தால்) என்று குறிப்பிடப்படுகின்றன.
Trailing Space: செல்லில் கடைசி மதிப்பைப் பின்பற்றும் இடைவெளிகள் "பின்தொடரும் இடம்" (ஏதேனும் இருந்தால்) என்று அழைக்கப்படுகின்றன.
In-Between Space: இடையில் ஒவ்வொரு வார்த்தையின் இறுதி ஒலியையும் பின்பற்றும் இடைவெளிகள் இடைவெளிகள் என்று குறிப்பிடப்படுகின்றன. ஒவ்வொரு வார்த்தையும் இயல்புநிலையாக ஒரு இட எழுத்தைக் கொண்டிருக்க வேண்டும். In-Between Space என்பது எதையும் குறிக்கிறது.
பயனர் அந்த குறிப்பிட்ட கலத்தின் திருத்த பயன்முறையில் நுழையாவிட்டால் அவற்றைத் தெளிவாகக் காண முடியாது என்பதால், உரையின் தொடக்கத்திலும் முடிவிலும் உள்ள இடைவெளிகளை அகற்ற இந்த செயல்பாடு உதவியாக இருக்கும்.
NOTE:
LTRIM மற்றும் RTRIM நடைமுறைகளும் VBA இல் கிடைக்கின்றன. சரத்தின் இடது பக்கத்தில் இருந்து தேவையற்ற இடைவெளிகளை அகற்ற LTRIM செயல்பாட்டைப் பயன்படுத்தவும், மேலும் சரத்தின் ரிக்கில் இருந்து அவற்றை அகற்ற RTRIM செயல்பாட்டைப் பயன்படுத்தவும்.
Syntax
Parameter
String (Required): இந்த வாதம் அதிகப்படியான தலைமை, பின்தொடர்தல் மற்றும் விண்வெளி எழுத்துக்களுக்கு இடையில் அகற்றப்பட வேண்டிய சரத்தைக் குறிக்கிறது.
Return
The VBA TRIM function return the string after removing the leading, trailing, and in-between space characters from the specified string.
Points to Remember
- The VBA Trim & Worksheet Trim syntax is exactly the same.
- It can only remove leading & trailing spaces, not in-between spaces.
- We can trim huge sets of data in one shot without checking the number of extra spaces the cells have.
- There are very less or no chances that any extra space will get spared.
# TRIM Example 1: Eliminate the extra space characters from the String ” Hello, Hope you are enjoying this tutorial? “
எக்செல் விபிஏவில் உள்ள ட்ரிம் செயல்பாடு உரை அல்லது கலங்களிலிருந்து கூடுதல் இடைவெளிகளை அகற்ற பயன்படுகிறது, மேலும் இது வழக்கமான இடைவெளிகளுடன் ஒரு சர மதிப்பை உருவாக்குகிறது. VBA TRIM function ஐப் பயன்படுத்த ஒரு 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: The Moule window will be inserted. Start the program with the macro name followed by the declaration of the variable.
Refer to the following macro code:
- Sub TRIM_Function_Example1()
- ‘Declare the variable
- Dim MyStr As String
- End Sub
Step 4: Next, we will specify the TRIM function and pass the string we want to TRIM. Store the output of the TRIM function in the variable. Once done, we will display the result using VBA MsgBox.
- Sub TRIM_Function_Example1()
- ‘Declare the variable
- Dim MyStr As String
- ‘Using the Trim function to eliminate the unwanted space characters
- MyStr = Trim(” Hello, Hope you are enjoying this tutorial? “)
- ‘displaying the output
- MsgBox MyStr
- End Sub

Output
உங்கள் விசைப்பலகையில் F5 அழுத்துவதன் மூலம் அல்லது VBA ரிப்பன் கருவிப்பட்டியில் இருந்து ரன் விருப்பத்தைத் தேர்ந்தெடுப்பதன் மூலம் மேக்ரோவை இயக்கவும். Excel உடனடியாக Msg Box காண்பிக்கும்.
# TRIM Example 2: Eliminate the extra space characters from selected Excel cells using VBA button.
VBA மொழியின் பல வழிகளில் எழுதும் திறன் ஒரு பிளஸ்.மேக்ரோவை உங்கள் ஆக்டிவ் பொத்தானுடன் இணைக்கலாம், இது ஒவ்வொரு முறையும் நிகழ்வைக் கிளிக் செய்யும் போது அதை இயக்கும்.இந்த எடுத்துக்காட்டில், நாங்கள் உங்களைக் காண்போம்.
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 TRIM_Function_Example2()
- ‘Declare the variable
- Dim MyStr As Range
- ‘setting the variable with the selection value
- Set MyStr = Selection
- End Sub
Step 4: Since, we have to iterate the function to further cells, so will use the For loop. Inside that will trim the string and store the value in Excel cell. Once done, we will display a message note using VBA MsgBox.
- Sub TRIM_Function_Example2()
- ‘Declare the variable
- Dim MyStr As Range
- ‘setting the variable with the selection value
- Set MyStr = Selection
- ‘Using For loop to iterate each cell
- For Each cell In MyStr
- ‘Trimming the string using TRIM function
- cell.Value = WorksheetFunction.Trim(cell)
- Dim str As String
- str = Trim(“The text is Trimmed!”)
- MsgBox str
- Next
- End Sub

கீழே விளக்கப்பட்டுள்ளபடி, கீழ்தோன்றும் மெனுவில் காட்டப்பட்டுள்ள படிவம் கட்டுப்பாடுகள் மற்றும் ActiveX கட்டுப்பாடுகளைக் காண்பீர்கள்.விருப்பங்களின் பட்டியலிலிருந்து பொத்தானைத் தேர்ந்தெடுக்கவும்.

Using your mouse cursor, draw the button shape anywhere on your Excel worksheet. Assign a macro name, and you can also select from the list of created macros. Here we have selected Trim_Function_Example2. Click on OK.


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

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

As a result, you will notice all the extra unwanted space characters have been removed from the selected data and it Excel will throw the message as well of “The text is trimmed!”.
Eureka! We have successfully covered various examples, and now you can trim your text and easily get rid of unwanted space characters from your Strings. Go ahead and give it a try and share professional sheets with your colleagues.