Trim Variable

  • Thread starter Thread starter Les Stout
  • Start date Start date
L

Les Stout

Hi all, i have a string variable and i need to replace the first 12
places (Left side), which are 8 numeric (Variable) and 4 spaces,
(constant). Is it possible to do this and if so could you please help
with some code.

thanks in advance.

Les Stout
 
This is how I understand what you are asking, hope I have it right: You want
code that will "overwrite" the first 12 characters of your string, so these
characters will be erased and replaced with an 8 digit number that you have
in a different string variable and then 4 spaces. If that is it, then this
should do:
MyString = DigitString & " " & Right(MyString, Len(MyString)-12)
 
sStr = "12345678 The Big Dog"
sStr = Right(sStr,len(sStr)-12)

demo'd from the immediate window:

sStr = "12345678 The Big Dog"
sStr = Right(sStr,len(sStr)-12)
? sStr
The Big Dog
 
Sub Replace()
Dim sVar As String
Dim WhatEver As String

sVar = Right(sVar, Len(sVar) - 12)
WhatEver = "whatevruwant"
sVar = WhatEver & sVar
End Sub

Mike F
 
Back
Top