Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare 2 cells in excel by using vba

Tags:

excel

vba

I would like to compare 2 cells' value and see whether they are match or not. I know how to do it on excel but I dont' know how to put it vba code.

Input & output:

  1. The value of cell A1 is already in the excel.
  2. Manually enter a value in Cell B1.
  3. click on a button_click sub to see whether the value on 2 cells are the same or not.
  4. Show "Yes" or "No" on cell C1

Excel formula:

=IF(A1=B1,"yes","no")
like image 641
pexpex223 Avatar asked Jan 21 '15 15:01

pexpex223


1 Answers

Give this a try:

Sub CompareCells()
    If [a1] = [b1] Then
        [c1] = "yes"
    Else
        [c1] = "no"
    End If
End Sub

Assign this code to the button.

like image 156
Gary's Student Avatar answered Nov 08 '22 12:11

Gary's Student