Results 1 to 5 of 5

Thread: [RESOLVED] Need fast way to Format & Trim Values or add formulas in Column / Range

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2005
    Posts
    222

    Resolved [RESOLVED] Need fast way to Format & Trim Values or add formulas in Column / Range

    I Have a column of cells with mixed formatting that I need to both trim leading and trailing spaces, and change the format to text.

    This works but is very slow.

    Thanks in advance. Needs to work in both Excel 2003 and 2007
    Code:
    Dim Rng As Range
    Dim tbl As Range
     
     Set tbl = Range("G2:G30000")
     
        For Each Rng In tbl
            On Error Resume Next
         
                Rng.NumberFormat = "@"
                Rng = Trim(Rng)
        Next
    Can this be done with the find method ? This is what I have so far -> I know using the asterisk is wrong.
    Code:
      Dim c As Range, firstAddress As String
      Dim Anyvalue
      Anyvalue = "*" '<-What can I put here so I can perform an operation on every cell?
      On Error Resume Next
      Set c = .Find(Anyvalue, LookIn:=xlValues)
     
    With ActiveSheet.Range("G2:G30000")
        If Not c Is Nothing Then
             firstAddress = c.Address
          Do
            c.NumberFormat = "@"
            c = Trim(c)
           
        Set c = .FindNext(c)
        
           Loop While Not c Is Nothing And c.Address <> firstAddress
       End If
    End With
    Last edited by SQLADOman; Jun 15th, 2010 at 03:42 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width