I want to compare two A and B columns with each other and highlight A column has this unqiue value and B column has this unique value in Microsoft Excel
Loading
I want to compare two A and B columns with each other and highlight A column has this unqiue value and B column has this unique value in Microsoft Excel
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal YelveRank #178 · 13.6K reputationPosted Jan 18, 2023, 7:41 AM EST
please refer below link, hope this will help
https://www.simplilearn.com/tutorials/excel-tutorial/compare-two-columns-in-excel#:~:text=Navigate%20to%20the%20%22Home%22%20option,matching%20values%20or%20unique%20values.
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Jan 18, 2023, 7:58 AM EST
Hi Krunal,
you need to open the Excel file and after comparison use the Range.Interior.Color property to change the background color of that cell to highlight it. Here is the code:
public void CompareExcelSheet(string excelFilePath) { Application excelApp = new Application(); Workbook workbook = excelApp.Workbooks.Open(excelFilePath); try { Worksheet worksheet = workbook.Sheets[1]; for (int i = 1; i <= worksheet.UsedRange.Rows.Count; i++) { var columnAValue = worksheet.Cells[i, 1].Value; var columnBValue = worksheet.Cells[i, 2].Value; if (columnAValue != null && columnBValue != null) { if (!columnAValue.Equals(columnBValue)) { // Change the background color of the unique value in column A to yellow worksheet.Cells[i, 1].Interior.Color = XlRgbColor.rgbYellow; // Change the background color of the unique value in column B to green worksheet.Cells[i, 2].Interior.Color = XlRgbColor.rgbGreen; } } } } catch (Exception ex) { } finally { workbook.Save(); excelApp.Quit(); } } //Method Calling: CompareExcelSheet(@"YourPath\CompareTable.xls");Aravind GovindarajRank #430 · 5.8K reputationPosted Jan 18, 2023, 10:08 AM EST
Please follow the below link
https://stackoverflow.com/questions/51770401/how-to-compare-two-cell-values-in-separate-columns-and-highlight-the-difference