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

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.
So you just want a procedure to return all of the strings within the range D2:D2001 excluding the first character?

Code:
Sub CutFirstChar()
Dim rng As Range
Dim cell As Range
Dim txt As String


Set rng = Range("D2:D2001")


    For Each cell In rng
        txt = Mid(cell.Value, 2)
        cell.Value = txt
    Next cell
End Sub

You could just use an Excel formula for this as well
=MID(D2, 2, LEN(D2)-1)
Then drag it down?

Is this what you are looking for??
 
Upvote 0
Thanks for your comments. This is only one part of a very large macro which produces a journal output file, having moved data from various places and collated it. My issue is still with removing the first character from a range of cells with varying lengths.
 
Upvote 0
Can you explain in what way things are not working, also please post some samples of the data you are working with.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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