I would like to have a vba code that will trim string.
Example:
When I enter Benjamin in cell A1, "Ben" will appear in C1.
Please help. Thank you.
I would like to have a vba code that will trim string.
Example:
When I enter Benjamin in cell A1, "Ben" will appear in C1.
Please help. Thank you.
You need to be more specific about your problem. To many of us, the solution to what you stated is just a simple formula of "=Left(A1,3)" placed in cell C1.
Does this need to work for every row in that worksheet? And how do you determine the trim? Is it always only taking the first 3 letters?
Thank you for your respond. I know how to use the Trim function and apply it on the cell. I just don't know how I can turn that into vba code.
This is really what i want:
once I entered the name "Benjamin" then hit ENTER key, VBA code should right away exeuted so that on C1 it will appear "Ben". This is just a sample for me to start my vba code. Once I got the code I will try to expand it myself. Thank you.
Thank you for your respond. I know how to use the Trim function and apply it on the cell. I just don't know how I can turn that into vba code.
This is really what i want:
once I entered the name "Benjamin" then hit ENTER key, VBA code should right away exeuted so that on C1 it will appear "Ben". This is just a sample for me to start my vba code. Once I got the code I will try to expand it myself. Thank you.
Hi, itselflearn,
you might like to use the Worksheet_Change-event for this. Right click on the worksheet tab, choose View Code, paste the code into teh code window:
Code will only work on a single cell in Column A at a time, check if there is a value in Column A and abbreviate that to 3 characters. If the value from the cell is deleted, the value in COlumn C is deleted too.![]()
Please Login or Register to view this content.
Ciao,
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
So I'll assume you have got the worksheet_change event working already, you can try adding this:
But of course this is just simply hard coding the values, if you want to trim it to only the first 3 letters, use something like this:![]()
Please Login or Register to view this content.
Then again, this would only apply if you entered "Benjamin". But it's hard to suggest what you can do when you didn't really explain your whole scenario.![]()
Please Login or Register to view this content.
Hi HaHoBe. Thank you very much for your code. It worked perfectly.
Millz, I would like to thank you for your time. I know that you would have probably given me a different working code but i am sorry for not so clear on my post. I appreciated all your time and effort.
Thank you all.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks