Find values greater than 0 in database and replace with 1

triatomine

New Member
Joined
May 30, 2007
Messages
1
Hi all,

I am trying to find all values in a large database greater than zero and replace them with 1 for a binary analysis. I have tried using find but am having no luck with a range of values. Suggestions?

thanks!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi triatomine,

Here's a macro you can use to convert all non-zero numerical values in whatever range of cells you select to 1s.

Code:
Sub NonzeroToOne()
   'Changes all nonzero numerical values in the selected range to 1
   Dim Cell       As Range
   For Each Cell In Selection
      If IsNumeric(Cell) Then
         If Cell.Value <> 0 Then Cell.Value = 1
      End If
   Next Cell
End Sub

To install this macro in your workbook, go to the VBE (keyboard Alt-TMV), insert a new macro module (Alt-IM) and paste this code into the Code pane. To run the macro go back to Excel, select the range of cells you want the macro to process, and Alt-TMM.

Keep Excelling.

Damon
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,930
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top