![]() |
macro to remove spaces at the end of a cell
ok, here is a tough one i think. I have a file that i copy into excel every
day. while all the information is the same, in the B column there is a random amount of spaces included by the program that gives me the data. Thanks to Dave i now have a macro that I can use to compare two sheets for duplicates, problem is that its not finding the duplicates due to the different number of spaces.. anyone know how to make a macro that removes all the spaces? the values in the B columns are all different lengths. |
macro to remove spaces at the end of a cell
cLastRow = Cells(Rows.Count,"B").End(xlUp).Row For i = 1 To cLastRow Cells(i,"B").Value = Trim(Cells(i,"B").Value Next i -- HTH Bob Phillips "Michael A" wrote in message ... ok, here is a tough one i think. I have a file that i copy into excel every day. while all the information is the same, in the B column there is a random amount of spaces included by the program that gives me the data. Thanks to Dave i now have a macro that I can use to compare two sheets for duplicates, problem is that its not finding the duplicates due to the different number of spaces.. anyone know how to make a macro that removes all the spaces? the values in the B columns are all different lengths. |
macro to remove spaces at the end of a cell
you can use the function TRIM like this:
=TRIM(B1) or the folllowing macros: this if need to remove spaces at the beginning and the end as well as duplicate ones in the middle of the string: Sub test() Dim LastRow As Long, i As Long With ActiveSheet LastRow = .Cells(.Rows.Count, 2).End(xlUp).Row For i = 1 To LastRow .Cells(i, 2) = WorksheetFunction.Trim(.Cells(i, 2)) Next i End With End Sub or this if all spaces need to be removed: Sub test2() Dim rng As Range With ActiveSheet Set rng = Intersect(.UsedRange, .Columns("B")) If Not rng Is Nothing Then _ rng.Replace " ", "" End With End Sub Regards, KL "Michael A" wrote in message ... ok, here is a tough one i think. I have a file that i copy into excel every day. while all the information is the same, in the B column there is a random amount of spaces included by the program that gives me the data. Thanks to Dave i now have a macro that I can use to compare two sheets for duplicates, problem is that its not finding the duplicates due to the different number of spaces.. anyone know how to make a macro that removes all the spaces? the values in the B columns are all different lengths. |
macro to remove spaces at the end of a cell
Hi
Something like [B1] = trim([A1]) will remove blank spaces from either end of a text string. Regards Andrew Bourke Michael A wrote: ok, here is a tough one i think. I have a file that i copy into excel every day. while all the information is the same, in the B column there is a random amount of spaces included by the program that gives me the data. Thanks to Dave i now have a macro that I can use to compare two sheets for duplicates, problem is that its not finding the duplicates due to the different number of spaces.. anyone know how to make a macro that removes all the spaces? the values in the B columns are all different lengths. |
macro to remove spaces at the end of a cell
thank you both very much.. I know realize its columns A B and C .. so i could
do this couldln't I? Sub test2() Dim rng As Range With ActiveSheet Set rng = Intersect(.UsedRange, .Columns("A3:C")) If Not rng Is Nothing Then _ rng.Replace " ", "" End With End Sub "KL" wrote: you can use the function TRIM like this: =TRIM(B1) or the folllowing macros: this if need to remove spaces at the beginning and the end as well as duplicate ones in the middle of the string: Sub test() Dim LastRow As Long, i As Long With ActiveSheet LastRow = .Cells(.Rows.Count, 2).End(xlUp).Row For i = 1 To LastRow .Cells(i, 2) = WorksheetFunction.Trim(.Cells(i, 2)) Next i End With End Sub or this if all spaces need to be removed: Sub test2() Dim rng As Range With ActiveSheet Set rng = Intersect(.UsedRange, .Columns("B")) If Not rng Is Nothing Then _ rng.Replace " ", "" End With End Sub Regards, KL "Michael A" wrote in message ... ok, here is a tough one i think. I have a file that i copy into excel every day. while all the information is the same, in the B column there is a random amount of spaces included by the program that gives me the data. Thanks to Dave i now have a macro that I can use to compare two sheets for duplicates, problem is that its not finding the duplicates due to the different number of spaces.. anyone know how to make a macro that removes all the spaces? the values in the B columns are all different lengths. |
macro to remove spaces at the end of a cell
..Columns("A:C")
not ..Columns("A3:C") KL "Michael A" wrote in message ... thank you both very much.. I know realize its columns A B and C .. so i could do this couldln't I? Sub test2() Dim rng As Range With ActiveSheet Set rng = Intersect(.UsedRange, .Columns("A3:C")) If Not rng Is Nothing Then _ rng.Replace " ", "" End With End Sub "KL" wrote: you can use the function TRIM like this: =TRIM(B1) or the folllowing macros: this if need to remove spaces at the beginning and the end as well as duplicate ones in the middle of the string: Sub test() Dim LastRow As Long, i As Long With ActiveSheet LastRow = .Cells(.Rows.Count, 2).End(xlUp).Row For i = 1 To LastRow .Cells(i, 2) = WorksheetFunction.Trim(.Cells(i, 2)) Next i End With End Sub or this if all spaces need to be removed: Sub test2() Dim rng As Range With ActiveSheet Set rng = Intersect(.UsedRange, .Columns("B")) If Not rng Is Nothing Then _ rng.Replace " ", "" End With End Sub Regards, KL "Michael A" wrote in message ... ok, here is a tough one i think. I have a file that i copy into excel every day. while all the information is the same, in the B column there is a random amount of spaces included by the program that gives me the data. Thanks to Dave i now have a macro that I can use to compare two sheets for duplicates, problem is that its not finding the duplicates due to the different number of spaces.. anyone know how to make a macro that removes all the spaces? the values in the B columns are all different lengths. |
All times are GMT +1. The time now is 09:08 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com