+ Reply to Thread
Results 1 to 4 of 4

Thread: How to change cells in Selection to values

  1. #1
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    9

    How to change cells in Selection to values

    I changed the formula into value with the first codes below. This code, however, has some limitation. The value of the selected cells which starts with 0, for example, 0022111, will be turned into 22111 with this code. So I came up with the second one. What would you do if it were you?

    With Range("D4", Range("D65536").End(xlUp)).Offset(0, 1) 
         
        .Formula = "=LEFT(RC[-1],FIND(""/"",RC[-1])-1)" 
        .Value = .Value 
    End With
    With Range("D4", Range("D65536").End(xlUp)).Offset(0, 1) 
         
        .Formula = "=LEFT(RC[-1],FIND(""/"",RC[-1])-1)" 
        .Copy 
    End With
    
    Selection.PasteSpecial Paste:=xlPasteValues
    Last edited by alexxgalaxy; 09-17-2011 at 09:48 AM.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: How to change cells in Selection to values

    Maybe
    With Range("D4", Range("D65536").End(xlUp)).Offset(0, 1)
         
        .Formula = "=LEFT(RC[-1],FIND(""/"",RC[-1])-1)"
        .Value = Format(.Value, "0000000")
    End With
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    09-16-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: How to change cells in Selection to values

    Quote Originally Posted by royUK View Post
    Maybe

    Thanks Roy but there is still limitation. The codes above can handle the example "0022111" I quoted but the real life case is there is no fix length for the value of every cells in selection. It could take six spaces as it did in my example but it could also take ten or even more.
    Last edited by alexxgalaxy; 09-17-2011 at 08:04 PM.

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: How to change cells in Selection to values

    Please don't quote whole posts. You didn't say that the the values were varying lengths
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ 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.2.0