If you were me or if you were I which is grammatically correct?

You're using the predicate nominative, so the pronoun should technically be in the nominative case (i.e. "If you were I"), but English speakers almost universally say and write "If you were me." "If you were I" sounds very stilted and many grammarians concede that the rule is changing.