Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default RTrim as a variable

I would like to use RTrim
to remove spaces from a list of single words.

Every example of RTrim I can find on the web
seems to be for a paticular fixed string like "Hello World ".

If I want to use: RTrim( text )
with 'text' as a variable
to loop down a list, if possible
and remove the trailing spaces
can I substitute something for 'text'
to identify the cell contents ?

That is, how would the following look?

Sub Macro1()
Do Until ActiveCell.Formula = ""
ActiveCell.Offset(1, 0).Select
RTrim( text )
Loop

Thank you,
Emory
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default RTrim as a variable

something like this may work if your data is in column A


Option Explicit
Dim rText As String
Dim LastRow As Long
Dim i As Long
Sub Macro1()
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("a1").Select
For i = 1 To LastRow
ActiveCell.Formula = RTrim(ActiveCell.Formula)
Next i

End Sub

--


Gary


"Emory Richter" wrote in message
om...
I would like to use RTrim
to remove spaces from a list of single words.

Every example of RTrim I can find on the web
seems to be for a paticular fixed string like "Hello World ".

If I want to use: RTrim( text )
with 'text' as a variable
to loop down a list, if possible
and remove the trailing spaces
can I substitute something for 'text'
to identify the cell contents ?

That is, how would the following look?

Sub Macro1()
Do Until ActiveCell.Formula = ""
ActiveCell.Offset(1, 0).Select
RTrim( text )
Loop

Thank you,
Emory



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default RTrim as a variable

Hi Gary,

Your procedure only acts on the A1 cell as your code uses the instruction:

ActiveCell.Formula = RTrim(ActiveCell.Formula)


and, having pre-selected A1, you do not change the active cell.


---
Regards,
Norman



"Gary Keramidas" wrote in message
...
something like this may work if your data is in column A


Option Explicit
Dim rText As String
Dim LastRow As Long
Dim i As Long
Sub Macro1()
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("a1").Select
For i = 1 To LastRow
ActiveCell.Formula = RTrim(ActiveCell.Formula)
Next i

End Sub

--


Gary


"Emory Richter" wrote in message
om...
I would like to use RTrim
to remove spaces from a list of single words.

Every example of RTrim I can find on the web
seems to be for a paticular fixed string like "Hello World ".

If I want to use: RTrim( text )
with 'text' as a variable
to loop down a list, if possible
and remove the trailing spaces
can I substitute something for 'text'
to identify the cell contents ?

That is, how would the following look?

Sub Macro1()
Do Until ActiveCell.Formula = ""
ActiveCell.Offset(1, 0).Select
RTrim( text )
Loop

Thank you,
Emory





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default RTrim as a variable

Hi Emory,

It is rarely necessary or desirable to make selections.

Try something like:

'=====================
Sub Tester01()
Dim rng As Range
Dim rCell As Range

Set rng = Range("A1:A20") '<<========= CHANGE

For Each rCell In rng.Cells
With rCell
If Not .HasFormula Then
.Value = RTrim(.Value)
End If
End With
Next

End Sub
'<<=====================

---
Regards,
Norman



"Emory Richter" wrote in message
om...
I would like to use RTrim
to remove spaces from a list of single words.

Every example of RTrim I can find on the web
seems to be for a paticular fixed string like "Hello World ".

If I want to use: RTrim( text )
with 'text' as a variable
to loop down a list, if possible
and remove the trailing spaces
can I substitute something for 'text'
to identify the cell contents ?

That is, how would the following look?

Sub Macro1()
Do Until ActiveCell.Formula = ""
ActiveCell.Offset(1, 0).Select
RTrim( text )
Loop

Thank you,
Emory





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 364
Default RTrim as a variable

yes, i pasted old code and didn't notice. i thought i copied the code after
i changed it but i guess i didn't. this is what i came up with and didn't
end up posting

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To LastRow
Range("a" & LastRow).Select
ActiveCell.Formula = RTrim(ActiveCell.Formula)
LastRow = LastRow - 1
Next i

--


Gary


"Norman Jones" wrote in message
...
Hi Gary,

Your procedure only acts on the A1 cell as your code uses the
instruction:

ActiveCell.Formula = RTrim(ActiveCell.Formula)


and, having pre-selected A1, you do not change the active cell.


---
Regards,
Norman



"Gary Keramidas" wrote in message
...
something like this may work if your data is in column A


Option Explicit
Dim rText As String
Dim LastRow As Long
Dim i As Long
Sub Macro1()
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("a1").Select
For i = 1 To LastRow
ActiveCell.Formula = RTrim(ActiveCell.Formula)
Next i

End Sub

--


Gary


"Emory Richter" wrote in message
om...
I would like to use RTrim
to remove spaces from a list of single words.

Every example of RTrim I can find on the web
seems to be for a paticular fixed string like "Hello World ".

If I want to use: RTrim( text )
with 'text' as a variable
to loop down a list, if possible
and remove the trailing spaces
can I substitute something for 'text'
to identify the cell contents ?

That is, how would the following look?

Sub Macro1()
Do Until ActiveCell.Formula = ""
ActiveCell.Offset(1, 0).Select
RTrim( text )
Loop

Thank you,
Emory







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
variable height variable width stacked bar charts ambthiru Charts and Charting in Excel 3 January 18th 06 11:41 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
I can't seem to use RTRIM or LTRIM in Excel 2002. I want to trim. Pam New Users to Excel 3 December 2nd 04 12:08 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM


All times are GMT +1. The time now is 03:44 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"