The study presents a method for taking the heterogeneity of the stand into account in the optimisation of stand management. Heterogeneity refers to within-stand variation in stand density and/or other characteristics. A set of plots, corresponding to different sub-areas of the stand, represents the stand in calculations. Cuttings and other treatments of the plots are done simultaneously. The method was used to analyse how the optimal management depends on the heterogeneity of a Norway spruce (Picea abies (L.) Karst.) and Scots pine (Pinus sylvestris L.) stand. The results supported the hypothesis that the heterogeneity of a stand decreases its optimal prior-thinning density. Also the remaining stand basal areas were lower in heterogeneous stands, especially in spruce. The effect of stand heterogeneity prior to the first commercial thinning still affected the timing of the second thinning, which had to be conducted earlier and at lower prior-thinning basal areas in heterogeneous stands. This happened despite the fact that the first thinning greatly decreased the within-stand variation in stand basal area. In addition, heterogeneity decreased the soil expectation value, net income and timber harvests.