+ Reply to Thread
Results 1 to 5 of 5

Clean the value of a cell

  1. #1
    Forum Contributor
    Join Date
    03-09-2009
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    128

    Clean the value of a cell

    Hi,

    I have a cell value with " '2005"

    I want to clean away the spaces and ' in the cell value.
    Is there a Substitute function in VBA?

  2. #2
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: Clean the value of a cell

    One way to do it is to use the Application.Worksheet method.
    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: Clean the value of a cell

    Sorry - hit Submit instead of Preview

    the other method is to use Replace
    Please Login or Register  to view this content.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Clean the value of a cell

    Hi

    It's not clear whether your cell includes the double quotes or not I'm assuming not and that you just have: space ' 2005

    In which case I'm not sure why you need a VBA solution. Why not just use an Excel compound formula? e.g with your example in A1

    Please Login or Register  to view this content.
    If you need VBA then you could use the REPLACE instruction.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Forum Contributor
    Join Date
    03-09-2009
    Location
    Oslo, Norway
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Clean the value of a cell

    Quote Originally Posted by Richard Buttrey View Post
    Hi

    It's not clear whether your cell includes the double quotes or not I'm assuming not and that you just have: space ' 2005

    In which case I'm not sure why you need a VBA solution. Why not just use an Excel compound formula? e.g with your example in A1

    Please Login or Register  to view this content.
    If you need VBA then you could use the REPLACE instruction.

    HTH

    I know this, however I need it as it is part of a larger macro. But thanks for the help.

    I also need some help with a for each loop.


    Sheets("Historic - Data Feed").Select
    Cells.Find(What:="Month", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False).Activate
    ActiveCell.Offset(-1, 0).Select
    Selection = Replace(Selection, "'", "")
    Selection = Replace(Selection, " ", "")

    I need the above code to loop through all the cells which contains "Month". And do the replace part.

    How can I get it to go to the next occurance of Month?

    THanks for all the help so far

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1