VBA to replace values with Yes or No

General Ledger

Active Member
Joined
Dec 31, 2007
Messages
460
Dear All,

I am looking for a better way to change a list of values to Yes or No.

I have the below code which works fine. It examines the value on each line one at a time. This takes a long time since I have many records.


Code:
'   Convert Exclude from a Value to Text (Yes or No)
 
    Range("k2").Activate
    Do Until IsEmpty(ActiveCell)
        If ActiveCell.Value < 0 Then
            ActiveCell.Value = "Yes"
        Else:  ActiveCell.Value = "No"
        End If
        ActiveCell.Offset(1, 0).Activate
    Loop

Is there a faster way?

Thanks,

GL
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Code:
Sub test()
    With Range("K2", Range("K2").End(xlDown))
        .Value = Evaluate("if(" & .Address & "<0,""yes"",""no"")")
    End With
End Sub
 
Upvote 0
Here's another

Code:
Sub val2Text()
    Dim c, lr
    On Error Resume Next
    Application.ScreenUpdating = False
    Set c = Range("K1")
    Set lr = Cells(Rows.Count, c.Column).End(xlUp)
    Set t = Range(c.Offset(1), lr)
    With c
        .AutoFilter
        .AutoFilter field:=c.column, Criteria1:="<0"
        t.SpecialCells(xlCellTypeVisible).Value = "Yes"
        .AutoFilter field:=c.column, Criteria1:="<>Yes"
        t.SpecialCells(xlCellTypeVisible).Value = "No"
        .AutoFilter
    End With
End Sub
 
Upvote 0
Wigi and Weaver,

Thanks to both of you for excellent solutions. When I posted the question I had in mind a solution much like the one Weaver offered. However, I used Wigi's solution because of its simplicity in that I could better understand it.

GL
 
Upvote 0
Thanks for the feedback.

Can you assess the speed of the macro - before and after the changes?
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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