Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All,

In Excel, first I would like to check if the value inside the cell that comes under the Range (E2:E40) has the value "X" and if that particular cell has that value, then the value inside that cell should be changed to "Y". Is there any way to mention like this using VBA?

What I have tried:

I was able to use the IF function in excel, but I was not able to figure out on how to do the same using VBA.
Posted
Updated 22-Jul-19 8:45am

1 solution

Yes, it is relatively simple.

Sub Macro1()
'
' Macro1 Macro
'

'Check the value in a range of cells is 5 < x < 20 and replace with 3.14
'On the active sheet the range contained the numbers 1 to 30
'select the sheet and simply run the macro

For Each c In Range("E1:E30")

    If c.Value > 5 Then
        If c.Value < 20 Then
        
        c.Value = 3.14
        
        End If
    End If
Next

End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900