![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
|
I have a column of names, but they are downloaded and each cell with a name in it has a large number of spaces before the name itself. So for example, the data in a cell would look like this: " Jimmy" Can anyone give me some code that will lok down this column (column G) and remove all the spaces before the names? I'd be really grateful for this Thanks |
|
|
|
|
|
#2 |
|
New Member
Join Date: Apr 2002
Posts: 6
|
Trim and then the cell reference, removes all extra spaces
|
|
|
|
|
|
#3 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
Hi joe
Try this Code:
Sub GoAwaySpaces()
Columns(7).EntireColumn.Insert
With Range("H1", Range("H65536").End(xlUp))
.Offset(0, -1).FormulaR1C1 = "=TRIM(RC[1])"
.Offset(0, -1) = .Offset(0, -1).Value
End With
Columns(8).EntireColumn.Delete
End Sub
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Where the wild roses grow
Posts: 285
|
Cheers
|
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: Brisbane, Down Under
Posts: 533
|
You can also try this if ALL names have spaces in front. Hilite the column,from the Data Menu, Text to Columns, select Delimited from the first window and Spaces from the second. Note the column immediately to the right must be vacant.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|