+ Reply to Thread
Results 1 to 11 of 11

how to replace the "Alt-Enter" character in a cell with sway "@"

Hybrid View

jmac1947 how to replace the... 03-04-2014, 03:40 AM
XOR LX Re: how to replace the... 03-04-2014, 03:53 AM
jmac1947 Re: how to replace the... 03-04-2014, 04:03 AM
XOR LX Re: how to replace the... 03-04-2014, 04:11 AM
TMS Re: how to replace the... 03-04-2014, 04:12 AM
Izandol Re: how to replace the... 03-04-2014, 04:36 AM
jmac1947 Re: how to replace the... 03-04-2014, 05:14 AM
jmac1947 Re: how to replace the... 03-04-2014, 05:20 AM
XOR LX Re: how to replace the... 03-04-2014, 05:39 AM
TMS Re: how to replace the... 03-04-2014, 05:45 AM
Izandol Re: how to replace the... 03-04-2014, 05:55 AM
  1. #1
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    how to replace the "Alt-Enter" character in a cell with sway "@"

    Hi Team,

    very simple request if you know the answer I am guessing

    have done a bit of searching but cannot find something that I can adapt.

    Ideally I would like to perform the action in VBA on a whole column but I can live with one row at a time as I need to do other things on a row by row basis anyway

    Thanks in advance

    Jmac

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    Hi,

    Maybe this:


    Sub DeleteALTENTER()
    
    Dim Rng As Range
    Dim LRow As Long
    
    LRow = Cells(Rows.Count, "A").End(xlUp).Row
    Set Rng = Range("A1:A" & LRow)
    
        For Each r In Rng
            
            If InStr(r.Value, Chr(10)) > 0 Then
                
                r.Value = Replace(r.Value, Chr(10), "@")
                
            End If
            
        Next r
        
    End Sub


    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    thanks XOR LX,

    as an aside, you use
        last_input_row = Cells(Rows.Count, "A").End(xlUp).Row
    where as I usually use
        last_input_row = Sheets(sheet_name).UsedRange.Rows.Count
    any comments on what method is "better" and perhaps in what circumstances??

    Sorry, I know this is slightly off topic but my defence is that I am trying to understand your posted solution

    jmac

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    Hi,

    I'm afraid I'm still a bit of an amateur when it comes to VBA so I couldn't comment on the perfomance difference between those two methods.

    Hopefully someone with a bit of expertise will pick up on this thread.

    Cheers

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,108

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    UsedRange can be unreliable as Excel "remembers" how many rows there have been. If you add and delete rows, Excel retains the highest value. Same with columns.

    So with UsedRange you may process more rows than actually have data.

    If you use End(xlUp) with a column that is fully populated, like a key field, it will locate the true last row.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    You may also try:
    range("A:A").Replace what:=chr(10), replacement:="@", lookat:=xlpart
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  7. #7
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    team, thanks for your quick responses.

    All of you have contributed to my learning (again it seems for all three of you) for which I am indebted.

    Both code solutions work exactly as they look like they should,

    @Izandol you certainly believe in letting "vba do the heavy lifting", I can think of many many instances where I could have used that simple line of code although to be fair to XOR LX I have used that construct or a simple "for loop" more times than I can count

    all three of you deserve the rep you are about to get, thanks again for your invaluable help

    Jmac

  8. #8
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    @izandol,

    sorry, last minute question.

    I assume that multiple cols can be handled by changing the "A:A" to say "A:B" and that I could just change the "what" and "replacement" values so say, replace every space with "@"

    Jmac

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    @Izandol Thanks for doing in one line of code what took me a dozen!!

    @Trevor Thanks for pointing that out.

    @JMac Appears we share the same level of stuck-in-For-Next-looping solutions!!

    Cheers

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,108

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    I assume that multiple cols can be handled by changing the "A:A" to say "A:B" and that I could just change the "what" and "replacement" values so say, replace every space with "@"
    Yes, and yes.

    And, for the question you haven't yet asked: you can change xlPart to xlWhole if you want to check only the entire contents of the cells rather than individual characters or words.

    Thanks for the rep

    Regards, TMS

  11. #11
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: how to replace the "Alt-Enter" character in a cell with sway "@"

    Also you may replace cell format.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cell.Replace "XY", Variant(I) & "XY" formulla builder not functioning
    By Leon V (AW) in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-13-2014, 07:11 AM
  2. Replies: 4
    Last Post: 11-17-2013, 12:05 PM
  3. [SOLVED] How to USE """"" cells count """"" change font color
    By austin123456 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2013, 06:14 AM
  4. [SOLVED] unable to enter "/" in cell as 1st character
    By RobMlr in forum Excel General
    Replies: 2
    Last Post: 03-27-2006, 12:30 AM
  5. [SOLVED] RE: unable to enter "/" in cell as 1st character
    By RobMlr in forum Excel General
    Replies: 0
    Last Post: 03-26-2006, 07:00 PM

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