Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Thursday, November 17, 2016

Excel : Compare Data in ColA with ColB In excel (Non sequential)

 Compare Data in ColA with ColB In excel (Non sequential)


Ref : How To Enable VBA to Enable VBA in Excel

Sub Deepak_compare_c1_c2()
'This code compares the values in ColA of sheet 1 with ColB in the same sheet
'ColA = Expected Value
'ColB = Actual Value
'Values in Col A can be anywhere in ColB it will be searched
'If values in the ColA is repeated Eg {1,4,4} then it will search for 2 repeated values in ColB 'Eg:{5,6,1,4,7,4} - here 1,4,4 all three are found


Dim row_count, sExp_val, bFlag, ilast_row_ColA, ilast_row_ColB
With ActiveSheet
ilast_row_ColA = .Cells(.rows.Count, "A").End(xlUp).Row ' Last used Row in ColA
End With
With ActiveSheet
ilast_row_ColB = .Cells(.rows.Count, "B").End(xlUp).Row ' last used Row in ColB
End With
MsgBox ("ColA =" & ilast_row_ColA & " ColB =" & ilast_row_ColB)
For i = 1 To ilast_row_ColA
bFlag = False
sExp_val = Cells(i, 1).Value
For j = 1 To ilast_row_ColB
If (sExp_val = Cells(j, 2).Value And Cells(j, 2).Interior.ColorIndex <> 15) Then
Cells(i, 1).Interior.Color = vbGreen
Cells(j, 2).Interior.ColorIndex = 15
bFlag = True
End If
If (bFlag = True) Then
Exit For
End If
Next
If (bFlag = False) Then
Cells(i, 1).Interior.Color = vbRed
End If
Next
MsgBox ("Done" & vbNewLine & "Red = not Found" & vbNewLine & "Green=Found" & vbNewLine & "Grey=Greyed Out once it is matched")

End Sub

Excel : Enable VBA in Excel

Enable VBA in Excel

To enable VBA
  1.  File > Options >Select Customise the Ribbon . 
  2. You then have tick the Developer box to allow the Developer icon to appear.

To allow the Excel to run programs included with spreadsheets. 
 File>Options > Trust Center > Trust Center Settings>Macro settings >select enable all macros.