Using TRIM with variable length fields

Maggielove

New Member
Joined
Apr 3, 2018
Messages
11
Is it possible to use TRIM where the field lengths are not consistent? I need to remove the first character of a field but the length varies between 4 and 8 characters, so wondered what the options were please.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
How about
=REPLACE(A1,1,1,"")
 
Upvote 0
Thanks for the reply. I did wonder about REPLACE, but I wasn’t sure if it would give me a blank text space in what would be a numeric field after the character was removed.
 
Upvote 0
It wont give a blank space, but it will return a string rather than a number. To coerce the value into a number, use
=--REPLACE(A1,1,1,"")
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0
Thanks for the reply. I am still not getting the results I need so I wondered if the range definition is something to do with it.
This code works, but only on fixed length, so how can I amend to include variable length of characters please?

Dim MyTrim As Range
Dim MyTop As Range
Set MyTrim = Range(“d2:d2001”)
For Each MyTop In MyTrim
MyTop = “=RIGHT(RC[1],4)”
Next MyTop
 
Upvote 0
Try put MyTop = MID(MyTop, 2)
This will set MyTop to equal the 2nd character up until the end character, as when you don't specifiy number of chars in the MID function it will go to the end of the string (in VBA not Excel)
 
Last edited:
Upvote 0
That is going to produce a specific number of characters because you ask it to produce a specific number of characters, ie 4. It is also very different to what you asked for in the first place and ignores the replies you had. You also dont need to use a loop to place a formula into a range of cells.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top