Good question! I have recorded five examples. Through a ballot of a company's enlisted men, typically a sergeant was elected to fill the position of junior second (third) lieutenant. Junior officers would usually just move up to fill a vacancy for first lieutenant or captain, but a vote might also be taken among the men to select a first lieutenant or even captain if there was no junior lieutenant available, or for some reason that individual was not considered suitable for higher rank. In all five cases there was no outside interference in the selections made.
Captain Robert E. Park of the 12th Alabama mentions just such an election of a sergeant to a junior lieutenant, but he also noted that he appointed the non-commissioned officers in his company, so in essence he decided the available pool of NCOs who might eventually be considered for election as an officer.