+ Reply to Thread
Results 1 to 17 of 17

Need to Replace Cell Values which are greater than 1

  1. #1
    Registered User
    Join Date
    10-29-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Need to Replace Cell Values which are greater than 1

    Hi,

    I would like to replace my cell values which are greater than 1 with 1.
    eg; if A1=15 I want to replace it as 1.
    if a cell value is 1 it should be 1.

    I need a sheet with only 1 or 0.

    Please help me to solve this problem.

    Thanks,

    George

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Need to Replace Cell Values which are greater than 1

    Try this:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-29-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need to Replace Cell Values which are greater than 1

    Solution

    Hi,

    It is working with this code,

    Open Macro

    Sub GreaterThanOne()
    Dim rCell As Range

    For Each rCell In Selection
    If IsNumeric(rCell) Then
    Select Case rCell
    Case Is > 0: rCell = 1
    Case Is < 0: rCell = 0
    End Select
    End If
    Next rCell

    End Sub

    To enter, press ALT & F11 to open the VBA editor.

    Insert > Module > Paste the above code

    Close the VBA editor


    In excel select the cells you wish to run the code on.

    Go to tools > macros > run macro
    Last edited by georgekmathew; 10-29-2013 at 03:23 AM.

  4. #4
    Registered User
    Join Date
    10-29-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need to Replace Cell Values which are greater than 1

    Thanks Milz,

    It is working partially.

    Even if It is working, it is replacing all cells those have data with 1.

  5. #5
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Need to Replace Cell Values which are greater than 1

    Yes, because I had no idea where do you want replaced, and whether only numbers.

    Revised code, if you need:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-29-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need to Replace Cell Values which are greater than 1

    No, It is not working Milz.

    There is no change happening.

    Quote Originally Posted by millz View Post
    Try this:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Need to Replace Cell Values which are greater than 1

    Are you quoting the correct post? In post #2, the code will run for all non-blank cells in the entire worksheet. In post #5, you have to select the cells that you want replaced, before running the code. Sorry about the mistake for post #5, add this line:
    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Need to Replace Cell Values which are greater than 1

    Quote Originally Posted by millz View Post
    Please Login or Register  to view this content.
    Really a bad example by not declaring variable properly and specifying property.
    It will do nothing.

    try
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-29-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need to Replace Cell Values which are greater than 1

    Thanks Milz.

    Now It is working perfectly. Small and Beautifull.

  10. #10
    Registered User
    Join Date
    10-29-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need to Replace Cell Values which are greater than 1

    Thanks Jindon; It is Working.

    Quote Originally Posted by jindon View Post
    Really a bad example by not declaring variable properly and specifying property.
    It will do nothing.

    try
    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Need to Replace Cell Values which are greater than 1

    georgekmathew,

    Let me just give you an advise.

    Not even try to copy the code posted when the variable are not declared.
    It will be sometime too risky for you.

  12. #12
    Registered User
    Join Date
    10-29-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need to Replace Cell Values which are greater than 1

    Thanks Jindon,

    Can you please tell me why it become too risky...

    Is there any security threats...or something else.

    Quote Originally Posted by jindon View Post
    georgekmathew,

    Let me just give you an advise.

    Not even try to copy the code posted when the variable are not declared.
    It will be sometime too risky for you.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Need to Replace Cell Values which are greater than 1

    OK, this is what I have experienced long time ago.

    People like you are asking codes and just copy/paste it to use it from various source.
    And I have posted like I always do, but that code required to declare a variable as Global.

    Accidentally, the name of the variable I used was used in other procedure without decalring the variable within that procedure.

    This will destroy everything.

    You know what I mean?

    So, if somebody post the code as a solution without declaring variable properly, ask him/her to declare the variable.

  14. #14
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Need to Replace Cell Values which are greater than 1

    Quote Originally Posted by jindon View Post
    Really a bad example by not declaring variable properly and specifying property.
    It will do nothing.
    Hi Jindon, thanks for your criticism. Will take note about it in the future.
    Last edited by millz; 10-29-2013 at 04:43 AM.

  15. #15
    Registered User
    Join Date
    10-29-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Need to Replace Cell Values which are greater than 1

    Thanks. Jindon

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Need to Replace Cell Values which are greater than 1

    georgekmathew

    You are welcome.

  17. #17
    Forum Contributor
    Join Date
    09-07-2013
    Location
    chennai
    MS-Off Ver
    Excel 2010
    Posts
    114

    Re: Need to Replace Cell Values which are greater than 1

    hi dude... use simple this if condition to slove this prob,

    =IF(A1>=1,1,0)

+ 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. I want to replace values greater than 200
    By wlan in forum Excel General
    Replies: 10
    Last Post: 09-30-2014, 10:59 AM
  2. Using Greater Than or Less than symbols to ectract cell values
    By GatorsBucs in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2013, 10:34 AM
  3. Adding values until one cell is greater than the other
    By 307Milkman in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-22-2013, 06:01 PM
  4. Replies: 4
    Last Post: 12-05-2011, 07:01 PM
  5. Replies: 3
    Last Post: 09-29-2010, 01:30 AM

Tags for this Thread

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