Bonjour,
Yes there is some rules about it...
Pronoun "en"
An indefinite or a partitive article plus a noun can be replaced by the pronoun "en".
"En" often means some or any in this context.
eg : Tu veux de la salade ? do you want any lettuce ?
Non, je n'en veux pas, merci. No, I don't want any, thank you.
The pronoun "en" may replace nouns used with expressions of quantity or numbers. In such cases, "en" may have no direct English equivalent.
eg : Tu as beaucoup de travail ? do you have a lot of work ?
J'en ai trop (en = de travail) I have too much.
Nicolas a des frères ? Does Nicolas have any brothers ?
Oui, il en a trois. (en = des frères) Yes, he has three (brothers)
En may replace the construction de (preposition) + noun or infinitive, but only when the noun is inanimate.
eg : Marie est-elle revenue de France ? Has Marie come back from France ?
Elle en revient demain. She's coming back (from there) tomorrow.
This is a first explanation...