Thanks Thanks:  0
Likes Likes:  0
Results 1 to 8 of 8

Thread: ready to use code

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    229
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi there,

    Hoping that someone can help me:

    I have a lot of data that i import into excel in csv format, which is untidy. I run the trim and proper functions on the cells.

    Is there a easy to write (or use) function that i could assign a button too, which would do this for me.

    Thanks

    Richard

  2. #2
    MrExcel MVP Damon Ostrander's Avatar
    Join Date
    Feb 2002
    Location
    Denver, Colorado USA
    Posts
    4,239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Richard,

    I don't know if this is exactly what you want, but here is a macro that will Trim and Proper the contents of all cells on the active worksheet:

    Sub TrimProper()
    ' Trims and uppercases the contents of all cells on the
    ' active worksheet
    Dim Cell As Range
    For Each Cell In ActiveSheet.UsedRange
    Cell.Value = UCase(Trim(Cell.Value))
    Next Cell
    End Sub
    Keep Excelling.

    Damon

    VBAexpert Excel Consulting
    LinkedIn Profile http://www.linkedin.com/pub/damon-ostrander/7/79/a93
    AllExperts Profile http://www.allexperts.com/ep/1059-30...-Ostrander.htm

  3. #3
    Board Regular
    Join Date
    Feb 2002
    Posts
    229
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Thanks Damon,

    How would i apply this to the selected range of cells.

    thanks again

    rich

  4. #4
    MrExcel MVP Damon Ostrander's Avatar
    Join Date
    Feb 2002
    Location
    Denver, Colorado USA
    Posts
    4,239
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi again Richard,

    To apply this to the selected cells, the code should be:

    Sub TrimProper()
    ' Trims and uppercases the contents of all selected cells on the
    ' active worksheet
    Dim Cell As Range
    For Each Cell In Selection
    Cell.Value = UCase(Trim(Cell.Value))
    Next Cell
    End Sub

  5. #5
    Board Regular
    Join Date
    Feb 2002
    Posts
    229
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: ready to use code

    HI

    this was a long time ago, but i have lost some data!

    this puts the items as uppercase, not in sentence case - i have tried amending the code by changing ucase to proper but i get a compile error

    any ideas please?

    thanks
    rich

  6. #6
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    73,092
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Default Re: ready to use code

    There is no Proper function in VBA, so you need to use the worksheet function, eg:

    Cell.Value = WorksheetFunction.Proper(Trim(Cell.Value))

  7. #7
    MrExcel MVP
    Moderator
    SydneyGeek's Avatar
    Join Date
    Aug 2003
    Location
    Sydney, Australia
    Posts
    12,255
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Default Re: ready to use code

    Just went through the Help. There is no Proper function in VBA, so you have to use the Excel version:
    Code:
    Sub TrimProper() 
    ' Trims and uppercases the contents of all selected cells on the 
    ' active worksheet 
    Dim Cell As Range 
    For Each Cell In Selection 
      Cell.Value = Application.Proper(Trim(Cell.Value)) 
    Next Cell 
    End Sub
    HTH
    Denis

  8. #8
    Board Regular
    Join Date
    Feb 2002
    Posts
    229
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: ready to use code

    great

    many thanks!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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