Automatically Change Cell Value Via Code

elsg

Active Member
Joined
Mar 16, 2013
Messages
295
Hi.
I need to have the result in VBA.


If the value of the cell in column "A" is equal to the same cell in Column "B" then in column "C" is written "OK"

A9=3 B9=3 then C9=OK

Value1Value2Result
10487
402402OK
2451
3815
257357
367367OK
400401
83131
64864
78378
183183OK
243311
86966
886886OK
10008

<colgroup><col width="64" span="3" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
This assumes your data for Value1 begin in A2.
Code:
Sub MarkMatchAsOK()
Dim lR As Long, vA As Variant, R As Range
lR = Range("A" & Rows.Count).End(xlUp).Row
Set R = Range("A2", "B" & lR)
vA = R.Value
Application.ScreenUpdating = False
For i = LBound(vA, 1) To UBound(vA, 1)
    If vA(i, 1) = vA(i, 2) Then R.Cells(i, 1).Offset(0, 2).Value = "OK"
Next i
End Sub
 
Upvote 0
Hi.
thanks for replying!
how do I start with the data on B7?
Column-BColumn-CColumn-E
Value1Value2Result
Row-B710487
Row-B8402402KO
Row-B92451
Row-B103838OK
Row-B11257357
Row-B12367367OK
Row-B13400401
Row-B1483131
Row-B1564864
Row-B1678378
Row-B17183183OK
Row-B18243311
Row-B1986966
Row-B20886886OK
Row-B2110008

<colgroup><col><col span="2"><col><col></colgroup><tbody>
</tbody>

<tbody>
</tbody>





































I try...
Code:
Sub MarkMatchAsOK()Dim lR As Long, vA As Variant, R As Range
lR = Range("B" & Rows.Count).End(xlUp).Row
Set R = Range("B7", "C" & lR)
vA = R.Value
Application.ScreenUpdating = False
For i = LBound(vA, 2) To UBound(vA, 2)
    If vA(i, 2) = vA(i, 3) Then R.Cells(i, 2).Offset(0, 4).Value = "Liberada"
Next i
End Sub

Thank you!!
 
Upvote 0
Code:
Sub MarkMatchAsOK()
Dim lR As Long, vA As Variant, R As Range, oRw As Long
lR = Range("B" & Rows.Count).End(xlUp).Row
Set R = Range("B7", "C" & lR)
vA = R.Value
Application.ScreenUpdating = False
For i = LBound(vA, 1) To UBound(vA, 1)
    If vA(i, 1) = vA(i, 2) Then R.Cells(i, 1).Offset(0, 2).Value = "OK"
Next i
End Sub
 
Upvote 0
Try:
Code:
Sub MarkMatchAsOK()
With [e7].Resize([b7].End(4).Row - 6)
.Formula = "=if(rc2=rc3,""Liberada"","""")"
.Value = .Value
End With
End Sub
Hope it helps.
 
Upvote 0

Forum statistics

Threads
1,203,269
Messages
6,054,482
Members
444,727
Latest member
Mayank Sharma

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