+ Reply to Thread
Results 1 to 5 of 5

Getting rid of char(160)

  1. #1
    Biff
    Guest

    Getting rid of char(160)

    Hi Folks!

    I recorded a macro to clean the range selected of char(160)'s and attached
    it to a button on one of my toolbars.

    It's not working. Here's the code from the macro recorder:

    Sub Clean160()

    Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

    End Sub

    The actual recorded code included as the first line:

    Range("A1:A10").Select

    I figured since that referenced a specific range I could just remove that
    line and since the next line starts with Selection, that referred to any
    range selected. Is that the problem?

    Also, how does the code:

    Selection.Replace What:=" ",

    know that " " is char(160) and not char(32)?

    I tried replacing =" " with =char(160) but that errored.

    Thanks!

    Biff




  2. #2
    Chip Pearson
    Guest

    Re: Getting rid of char(160)

    Biff,

    Try
    Selection.Replace what:=Chr(160), replacement:=" "

    or in the Replace dialog box, hold down the ALT key and type 0160
    on the numeric keypad (not the number keys above the letters).



    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com



    "Biff" <biffinpitt@comcast.net> wrote in message
    news:%23aiX7p9QGHA.2300@TK2MSFTNGP11.phx.gbl...
    > Hi Folks!
    >
    > I recorded a macro to clean the range selected of char(160)'s
    > and attached it to a button on one of my toolbars.
    >
    > It's not working. Here's the code from the macro recorder:
    >
    > Sub Clean160()
    >
    > Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart,
    > _
    > SearchOrder:=xlByRows, MatchCase:=False,
    > SearchFormat:=False, _
    > ReplaceFormat:=False
    >
    > End Sub
    >
    > The actual recorded code included as the first line:
    >
    > Range("A1:A10").Select
    >
    > I figured since that referenced a specific range I could just
    > remove that line and since the next line starts with Selection,
    > that referred to any range selected. Is that the problem?
    >
    > Also, how does the code:
    >
    > Selection.Replace What:=" ",
    >
    > know that " " is char(160) and not char(32)?
    >
    > I tried replacing =" " with =char(160) but that errored.
    >
    > Thanks!
    >
    > Biff
    >
    >
    >




  3. #3
    Biff
    Guest

    Re: Getting rid of char(160)

    Thanks, Chip!

    Selection.Replace what:=Chr(160)

    Worked!

    Biff

    "Chip Pearson" <chip@cpearson.com> wrote in message
    news:elRbG79QGHA.4976@TK2MSFTNGP11.phx.gbl...
    > Biff,
    >
    > Try
    > Selection.Replace what:=Chr(160), replacement:=" "
    >
    > or in the Replace dialog box, hold down the ALT key and type 0160 on the
    > numeric keypad (not the number keys above the letters).
    >
    >
    >
    > --
    > Cordially,
    > Chip Pearson
    > Microsoft MVP - Excel
    > Pearson Software Consulting, LLC
    > www.cpearson.com
    >
    >
    >
    > "Biff" <biffinpitt@comcast.net> wrote in message
    > news:%23aiX7p9QGHA.2300@TK2MSFTNGP11.phx.gbl...
    >> Hi Folks!
    >>
    >> I recorded a macro to clean the range selected of char(160)'s and
    >> attached it to a button on one of my toolbars.
    >>
    >> It's not working. Here's the code from the macro recorder:
    >>
    >> Sub Clean160()
    >>
    >> Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
    >> SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    >> ReplaceFormat:=False
    >>
    >> End Sub
    >>
    >> The actual recorded code included as the first line:
    >>
    >> Range("A1:A10").Select
    >>
    >> I figured since that referenced a specific range I could just remove that
    >> line and since the next line starts with Selection, that referred to any
    >> range selected. Is that the problem?
    >>
    >> Also, how does the code:
    >>
    >> Selection.Replace What:=" ",
    >>
    >> know that " " is char(160) and not char(32)?
    >>
    >> I tried replacing =" " with =char(160) but that errored.
    >>
    >> Thanks!
    >>
    >> Biff
    >>
    >>
    >>

    >
    >




  4. #4
    Registered User
    Join Date
    01-27-2011
    Location
    Pennsylvania, US
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Getting rid of char(160)

    I use a simple formula:

    =TRIM(SUBSTITUTE(cell reference,CHAR(160),CHAR(32)))

  5. #5
    Registered User
    Join Date
    01-28-2020
    Location
    Newark, DE
    MS-Off Ver
    2016
    Posts
    1

    Re: Getting rid of char(160)

    Biff (and others):

    If working in VBA use the chr() function
    If working in an Excel worksheet formula, use the CHAR() function

    They are basically identical functions, but operate in difference contexts.

+ 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