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
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
Try this:
Please Login or Register to view this content.
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.
Thanks Milz,
It is working partially.
Even if It is working, it is replacing all cells those have data with 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.
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.
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.
Thanks Milz.
Now It is working perfectly. Small and Beautifull.
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.
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.
Thanks. Jindon
georgekmathew
You are welcome.
hi dude... use simple this if condition to slove this prob,
=IF(A1>=1,1,0)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks