Driven Steel H-piles are commonly used in the deep foundation of being cost-effective and easy in workmanship. The post-driving residual stresses acting on the pile could be large when being driven in cohesionless sands, significantly affecting its compressive strength. Current design methods, mostly based on the empirical assumptions of using safety factors, are unable to consider the post-driving residual stresses on piles accurately and usually very conservative in practical applications. Such consideration is further complicated when the pile is embedded in layered sands. Moreover, the soil-structure interaction (SSI) between pile and ground medium is usually complicated in the analysis and should be appropriately considered in a successful design. This paper proposes a line-finite-element implementation method, based on the Euler-Bernoulli pile element formulations, for robustly and efficiently analyzing the driven steel H-piles in layered sands with explicitly modelling the SSI. The effects resulting from the post-driving residual stresses are considered in the total potential energy equation for generating the secant relations. The derivation procedure is elaborated with details. Consequentially, verification examples are given for validating the accuracy of the proposed method. This work would be helpful for improving the numerical efficiency and accuracy for designing the steel H-piles in layered sands.