Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Trim Difficulties

I am trying to write a code that will remove a blank character in the from
the left side of cells in a particular range. After several permutations and
trials, I only get the first cell's value pasted into all the cells in the
rage.

Here is the lastest code I have tried:

Sub SpaceRemover()

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = ActiveCell
trimstring = Trim(mystring)
MyRange = trimstring

Next i

End Sub


I have also tried LTrim with the same results, . . .

Any help would be greatly appreciated,

Will
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Trim Difficulties

i.value = trimstring

--
Jim
"WillRn" wrote in message
...
|I am trying to write a code that will remove a blank character in the from
| the left side of cells in a particular range. After several permutations
and
| trials, I only get the first cell's value pasted into all the cells in the
| rage.
|
| Here is the lastest code I have tried:
|
| Sub SpaceRemover()
|
| Dim mystring, trimstring
| Dim i As Range
| Dim MyRange As Range
| Set MyRange = Range("F56:F132")
|
| For Each i In MyRange
|
| mystring = ActiveCell
| trimstring = Trim(mystring)
| MyRange = trimstring
|
| Next i
|
| End Sub
|
|
| I have also tried LTrim with the same results, . . .
|
| Any help would be greatly appreciated,
|
| Will


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Trim Difficulties


"WillRn" schrieb im Newsbeitrag
...
I am trying to write a code that will remove a blank character in the from
the left side of cells in a particular range. After several permutations
and
trials, I only get the first cell's value pasted into all the cells in the
rage.

Here is the lastest code I have tried:

Sub SpaceRemover()

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = ActiveCell
trimstring = Trim(mystring)
MyRange = trimstring

Next i

End Sub


I have also tried LTrim with the same results, . . .

Any help would be greatly appreciated,

Will


Hi Will,

replace the following in the loop:

For Each i In MyRange

mystring = i ' get current cell value
trimstring = Trim(mystring) ' trim value
i = trimstring ' write back to current
cell

Next i


cheers,
Stephan


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trim Difficulties

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = i.value
trimstring = Trim(mystring)
MyRange = trimstring

Next i

End Sub

--
Regards,
Tom Ogilvy

"WillRn" wrote in message
...
I am trying to write a code that will remove a blank character in the from
the left side of cells in a particular range. After several permutations

and
trials, I only get the first cell's value pasted into all the cells in the
rage.

Here is the lastest code I have tried:

Sub SpaceRemover()

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = ActiveCell
trimstring = Trim(mystring)
MyRange = trimstring

Next i

End Sub


I have also tried LTrim with the same results, . . .

Any help would be greatly appreciated,

Will



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Trim Difficulties

This should do it if you alter your macro:

Sub SpaceRemover()

Dim i As Range
Dim MyRange As Range

Set MyRange = Range("F56:F132")

For Each i In MyRange.Cells
i = Trim(i)
Next i

End Sub


I think something like this will be faster though:

Sub test()

Dim arr
Dim i As Long

arr = Range("F56:F132")

For i = 1 To UBound(arr)
arr(i, 1) = Trim(arr(i, 1))
Next

Range("F56:F132") = arr

End Sub

RBS


"WillRn" wrote in message
...
I am trying to write a code that will remove a blank character in the from
the left side of cells in a particular range. After several permutations
and
trials, I only get the first cell's value pasted into all the cells in the
rage.

Here is the lastest code I have tried:

Sub SpaceRemover()

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = ActiveCell
trimstring = Trim(mystring)
MyRange = trimstring

Next i

End Sub


I have also tried LTrim with the same results, . . .

Any help would be greatly appreciated,

Will




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Trim Difficulties

Hi Will,
For Each i In MyRange

mystring = ActiveCell
trimstring = Trim(mystring)
MyRange = trimstring

Next i



for each i in myrange
i = trim(i)
next


arno

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Trim Difficulties

Sorry,

Still getting the same result with:

Sub SpaceRemover()

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("E8:E79")

For Each i In MyRange

mystring = ActiveCell
trimstring = Trim(mystring)
i.Value = trimstring

Next i

End Sub


"Jim Rech" wrote:

i.value = trimstring

--
Jim
"WillRn" wrote in message
...
|I am trying to write a code that will remove a blank character in the from
| the left side of cells in a particular range. After several permutations
and
| trials, I only get the first cell's value pasted into all the cells in the
| rage.
|
| Here is the lastest code I have tried:
|
| Sub SpaceRemover()
|
| Dim mystring, trimstring
| Dim i As Range
| Dim MyRange As Range
| Set MyRange = Range("F56:F132")
|
| For Each i In MyRange
|
| mystring = ActiveCell
| trimstring = Trim(mystring)
| MyRange = trimstring
|
| Next i
|
| End Sub
|
|
| I have also tried LTrim with the same results, . . .
|
| Any help would be greatly appreciated,
|
| Will



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Trim Difficulties

Thanks!,

This last one worked.

Will

"RB Smissaert" wrote:

This should do it if you alter your macro:

Sub SpaceRemover()

Dim i As Range
Dim MyRange As Range

Set MyRange = Range("F56:F132")

For Each i In MyRange.Cells
i = Trim(i)
Next i

End Sub


I think something like this will be faster though:

Sub test()

Dim arr
Dim i As Long

arr = Range("F56:F132")

For i = 1 To UBound(arr)
arr(i, 1) = Trim(arr(i, 1))
Next

Range("F56:F132") = arr

End Sub

RBS


"WillRn" wrote in message
...
I am trying to write a code that will remove a blank character in the from
the left side of cells in a particular range. After several permutations
and
trials, I only get the first cell's value pasted into all the cells in the
rage.

Here is the lastest code I have tried:

Sub SpaceRemover()

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = ActiveCell
trimstring = Trim(mystring)
MyRange = trimstring

Next i

End Sub


I have also tried LTrim with the same results, . . .

Any help would be greatly appreciated,

Will



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Trim Difficulties

one more change required:

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = i.value
trimstring = Trim(mystring)
i = trimstring

Next i

End Sub

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = i.value
trimstring = Trim(mystring)
MyRange = trimstring

Next i

End Sub

--
Regards,
Tom Ogilvy

"WillRn" wrote in message
...
I am trying to write a code that will remove a blank character in the

from
the left side of cells in a particular range. After several permutations

and
trials, I only get the first cell's value pasted into all the cells in

the
rage.

Here is the lastest code I have tried:

Sub SpaceRemover()

Dim mystring, trimstring
Dim i As Range
Dim MyRange As Range
Set MyRange = Range("F56:F132")

For Each i In MyRange

mystring = ActiveCell
trimstring = Trim(mystring)
MyRange = trimstring

Next i

End Sub


I have also tried LTrim with the same results, . . .

Any help would be greatly appreciated,

Will





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate Difficulties :: Amy :: Excel Worksheet Functions 7 May 3rd 09 08:22 PM
difficulties ernie Excel Discussion (Misc queries) 1 February 13th 06 08:39 PM
Difficulties with COUNTIF. Martin M Excel Worksheet Functions 5 June 18th 05 02:25 PM
VBA Trim and Application.worksheetfunction.Trim Hari Prasadh Excel Programming 3 January 19th 05 02:22 PM
Trim like worksheet Trim Bob Phillips[_5_] Excel Programming 0 August 20th 03 07:10 PM


All times are GMT +1. The time now is 03:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"