# Using TRIM with variable length fields

#### Maggielove

##### New Member
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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
=REPLACE(A1,1,1,"")

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.

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,"")

That’s great. Many thanks for your help ?

You're welcome & thanks for the feedback

You could also use MID:
=--MID(A1,2,8)

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

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:
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.

Replies
5
Views
182
Replies
1
Views
237
Replies
0
Views
107
Replies
2
Views
251
Replies
4
Views
104

1,218,560
Messages
6,143,199
Members
450,469
Latest member
brent3162

### 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.

### Which adblocker are you using?

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

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