how do you write this in vba:
if cell value is greater than or equal to 2 change its value to 1
how do you write this in vba:
if cell value is greater than or equal to 2 change its value to 1
![]()
Sub ChangeIt() With Selection If .Value > 2 Then .Value = 1 End With End Sub
Gary's Student
what about a worksheet function?
With a worksheet function you would be putting 1 in a separate cell.
if A1 has the value, then in B1:
=IF(A1>=2,1,A1)
Thanks, seperate col is not a problem.
When i tried it in VBA it didnt work out for me...can you see what ive done wrong? ...
doesnt like the range i think.![]()
Workbooks("dataset1.xls").Sheets("Sheet3").Activate Range("F2:F11").Select With Selection If .Value > 2 Then .Value = 1 End With End Sub
We need to loop over the cells in the range:
![]()
Sub Demo() For Each cel In Workbooks("dataset1.xls").Sheets("Sheet3").Range("F2:F11") With cel If .Value > 2 Then .Value = 1 End With Next cel End Sub
brilliant thanks Jake!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks