def addMessage(row_num, valid, new_msg, messages):
    """ Add error message to the list of errors and set the validity"""

    if new_msg:
        if "Error" in new_msg:
            valid = False
        match = False

        for msg in messages:
            if new_msg == msg[1]:
                match = True
                if row_num + 1 != msg[0][-1]:
                    msg[0].append(row_num + 1)
                    return valid, messages

        if match == False:
            messages.append([[row_num + 1], new_msg])

    return valid, messages