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

Hi,

I would like to use a trim function to delete spaces before and after a
text in an entire column, but so far I could only use it in a cell:

Sub mac1()
Dim testing As String
testing = ActiveSheet.Range("A1")
ActiveSheet.Range("B1") = Trim(testing)
End Sub

Thanks for any help,

--
Domingos Junqueira


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Trim function in a macro

will this work for you?


Sub mac1()
Dim lastrow As Long
Dim cell As Range
Dim rng As Range
lastrow = Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
Set rng = Range("A1:A" & lastrow)
For Each cell In rng.Cells
cell.Offset(0, 1).Value = Trim(cell)
Next cell
End Sub

--


Gary


"Domingos Junqueira" wrote in message
...
Hi,

I would like to use a trim function to delete spaces before and after a
text in an entire column, but so far I could only use it in a cell:

Sub mac1()
Dim testing As String
testing = ActiveSheet.Range("A1")
ActiveSheet.Range("B1") = Trim(testing)
End Sub

Thanks for any help,

--
Domingos Junqueira



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Trim function in a macro

Trim will only act on a single string at a time. If you need to trim ALL
used cells in a column then apply a loop to sequentially trim each.
Something like....

Sub TrimColumn()
Dim LastRow as Long, xr as Long
LastRow = Cells(Rows.Count,1).End(xlup).Row
For xr = 1 to LastRow
Cells(xr,2) = Trim(Cells(xr,1))
Next xr
End Sub


--
Cheers
Nigel



"Domingos Junqueira" wrote in message
...
Hi,

I would like to use a trim function to delete spaces before and after

a
text in an entire column, but so far I could only use it in a cell:

Sub mac1()
Dim testing As String
testing = ActiveSheet.Range("A1")
ActiveSheet.Range("B1") = Trim(testing)
End Sub

Thanks for any help,

--
Domingos Junqueira




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
TRIM function JockW Excel Worksheet Functions 6 October 15th 08 10:41 PM
trim function [email protected] Excel Worksheet Functions 3 December 30th 05 03:00 AM
Need help with TRIM function Phil Excel Worksheet Functions 9 October 21st 05 08:02 PM
Trim function aehan Excel Worksheet Functions 3 January 25th 05 12:31 PM
Trim function in VBA molavi111 Excel Programming 3 September 22nd 04 05:59 PM


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