COUNTIF($A$5:$A$500,A5)>1
is only going to apply when cell A5 is matched somewhere else.
So I'd resolve this by having a separate conditional formatting rule for each cell. I'd generate this like this:
private HSSFSheetConditionalFormattingRule highlightIfMatch(HSSFSheetConditionalFormatting mycf, String cellId) {
HSSFConditionalFormattingRule rule = mycf.createConditionalFormattingRule("COUNTIF($A$5:$a$500,"+cellId+")>1");
//Go on to set your FontFormatting here
return rule;
}
Then replace your code with:
HSSFConditionalFormatting mycf = new_hire.getSheetConditionalFormatting();
for(int x=4; x<500; x++) {
HSSFRow row = new_hire.getRow(x);
if(null == row) {
row = new_hire.createRow(x);
}
HSSFCell cell = row.getCell(0); // 0 for column A
if(null == cell) {
cell = row.createCell(0);
}
String cellId = "A"+(x+1);
CellRangeAddress[] range = new CellRangeAddress(x, x, 0, 0); // 0 for column A
HSSFConditionalFormattingRule rule = highlightIfMatch(mycf, cellId);
range.addConditionalFormatting(range, rule);
}