1

I have a spreadsheet with approx 300 rows. Each row has about 4 columns, and each cell contains a numeric value. Each row corresponds to a respondent.

I want to get Excel, for each respondent, to highlight cells if there are repeated values.

For example:

╔══════╦══════╦══════╦══════╗
║ Col1 ║ Col2 ║ Col3 ║ Col4 ║
╠══════╬══════╬══════╬══════╣
║    2 ║    4 ║   12 ║    9 ║
║    2 ║    5 ║   23 ║    5 ║
╚══════╩══════╩══════╩══════╝

Here I want both 5 to be highlighted, but not the 2s because they are in different rows. However, I have 400 rows and it will take too long to select each row individually and set the Conditional Formatting. On the other hand, if I select the entire range and apply Conditional Formatting, Excel calculates the duplicates in the whole range, which isn’t useful. Another user suggested using the below Macro, but it isn’t working:

Sub NewCF()
  Range("B1:P1").Copy
  For Each r In Selection.Rows
      r.PasteSpecial (xlPasteFormats)
  Next r
  Application.CutCopyMode = False
End Sub

I've tried the Macro above, but for some reason, when I run it, all it does is to underline the cells selected, even though the ones in my range are not underlined.

Any Ideas to do this in a efficient way?

2 Answers 2

3

Any Ideas to do this in a efficient way?

I would create a Conditional Formatting rule with the following formula and format to fill the cell. This formula compares rows individually, not the whole range at once. (Note: I am making the assumption you are familiar with Conditional Formatting)

enter image description here

Then in the Rules Manager, change the Applies to to the range you want this applied to; for instance, $A$1:$D$300.

enter image description here

This will apply this rule to that range and check each row using the formula you entered. This will highlight the duplicates in each row.

enter image description here

4
  • Thank you, Charlie. I've tried your method and it works when my data starts at A1. However, I've tried to edit the formula so that it works when my range is, for example, C2:E10, and the conditional formatting won't work correctly anymore. For the example I've mentioned, I've tried setting the formula to: =countif(2:2,C2)>1 And the range it applies to to "=$C$2:$E$10" However the formatting does not apply correctly, and I'm afraid I don't understand why. Can you see what am I doing wrong? Commented Oct 3, 2016 at 16:22
  • 1
    I was able to get this to work as it should. The formatting is probably properly, but there may have been details missing from the original question. Your original question states you want to check the whole row and in your example there are four columns. In the above comment you mention three columns. The formula checks the entire row. If duplicates are found anywhere in the row it then triggers conditional formatting for the range specified. So, if there are values in columns beyond E matching other values in that row, it will trigger the conditional format in C2:E10.
    – CharlieRB
    Commented Oct 4, 2016 at 11:59
  • Was a solution found to do certain columns in a row rather than the whole row?
    – pee2pee
    Commented Nov 1, 2019 at 10:21
  • @pee2pee No. Since this is three years old and there wasn't any more input from the OP, I did not go any farther.
    – CharlieRB
    Commented Nov 24, 2019 at 0:14
0

This is pretty easy using the name manager. (Name manager is on formula ribbon) Make a new name with the cursor in the top left cell of your data. In my example, the data is from e6 to h6, so I have my cursor in e6

  • Test = IF(COUNTIF($E6:$H6,E6)>1,TRUE,FALSE)

What this is doing is counting how many other cells have the same value as the source cell. True means there is more than 1, false means there is not a duplicate Note: the name manager will expand this with the sheet names

select all the cells you want this to apply to, go to conditional formatting and select use an equation. The equation will be =test then select what formats you want it to use

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .