Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
RTrim as a variable
|
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
RTrim as a variable
|
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
variable height variable width stacked bar charts | Charts and Charting in Excel | |||
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? | Excel Worksheet Functions | |||
Run-time error '91': "Object variable or With block variable not set | Excel Programming | |||
I can't seem to use RTRIM or LTRIM in Excel 2002. I want to trim. | New Users to Excel | |||
Cells.Find error Object variable or With block variable not set | Excel Programming |