7 – 14.<\/strong> For each\nCell (in our case Row) in the first column we are going to compare the cell in\nthe same row, but the second column. What\nwe have to remember is that the comparison is case-sensitive.<\/p>\n\n\n\nThere is also a condition (fcCell.Value\n<> “”) that the cells\ncan\u2019t be empty, otherwise, they would\nhighlight cells in the selection that are empty.<\/p>\n\n\n\n
10 – 11.<\/strong> If all\nconditions are met both cells are highlighted.<\/p>\n\n\n\nAs I mentioned earlier, the comparison works only if both\nvalues are exactly the same, so Austria<\/strong>\nis not austria<\/strong>\nin this case.<\/p>\n\n\n\nCase insensitive<\/h3>\n\n\n\n There are two simple ways, you can make case-insensitive\ncomparisons.<\/p>\n\n\n\n
First option<\/strong><\/p>\n\n\n\nWhile making a comparison make the case of both values\nlowercase (or uppercase) run the code.<\/p>\n\n\n\n
Change<\/p>\n\n\n\n
If fcCell.Value = scCell.Value<\/code><\/pre>\n\n\n\nTo<\/p>\n\n\n\n
If LCase(fcCell.Value) = LCase(scCell.Value)<\/code><\/pre>\n\n\n\nSecond option<\/strong><\/p>\n\n\n\nInstead of changing values to lowercase, you can add the following code as the very first line of our code (before subroutine).<\/p>\n\n\n\n
Option Compare Text<\/code><\/pre>\n\n\n\nIt\u2019s going to make all text comparisons case-insensitive.<\/p>\n\n\n\n <\/figure>\n\n\n\nHighlight all matching cells<\/h2>\n\n\n\n In the last part of this tutorial, let\u2019s create a subroutine that\u2019s going to highlight every cell that has a match in the other column, but doesn\u2019t have to be restricted to the same row.<\/p>\n\n\n\n
Sub CompareColumnsCaseSensitive()\n Set myRange = Selection\n myRange.Interior.Color = xlNone\n Set firstColumn = myRange.Columns(1)\n Set secondColumn = myRange.Columns(2)\n \n For Each fcCell In firstColumn.Rows\n For Each scCell In secondColumn.Rows\n If fcCell.Value = scCell.Value And fcCell.Value <> \"\" Then\n fcCell.Interior.Color = vbGreen\n scCell.Interior.Color = vbGreen\n End If\n Next\n Next\nEnd Sub<\/code><\/pre>\n\n\n\nThis give us the following result.<\/p>\n\n\n\n <\/figure>\n\n\n\nAdd this line at the beginning of the script.<\/p>\n\n\n\n
Option Compare Text<\/code><\/pre>\n\n\n\n <\/figure>\n\n\n\nIf you want to see more example on how to deal with\nduplicates, you can read this\ntutorial<\/a>. There, you\u2019ll learn how to highlight columns, that have different\nsizes, with different colors.<\/p>\n","protected":false},"excerpt":{"rendered":"There are a few ways to compare columns in Excel. In this tutorial, I\u2019ll present different ways you can achieve this. Row by…<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[170,190],"yoast_head":"\n
Compare Two Columns in Excel<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n