A method to measure the complex compliance (or modulus) of linearly viscoelastic materials is presented using nanoindentation with a spherical indenter. The Hertzian solution for an elastic indentation problem, in combination with a hereditary integral operator proposed by Lee and Radok (Journal of Applied Mechanics 27, 1960, 438-444) for the situation of non-decreasing indentation contact area, was used to derive formulas for the complex viscoelastic functions in the frequency-domain. The formulas are most suitable for frequencies lower than a frequency limit such that the condition of non-decreasing contact area holds; they are reasonably good approximation at higher frequencies under which decreasing contact area occurs and the Ting (Journal of Applied Mechanics 33, 1966, 845-854) approach for arbitrary contact area history is needed. Nanoindentation tests were conducted on both polycarbonate and polymethyl methacrylate under a harmonic indentation load superimposed on either step or ramp indentation load, while the resulting displacement under steady state was recorded. The load and displacement data at each frequency were processed using the derived formulas to determine the viscoelastic functions in the frequency-domain. The same materials were also tested using a dynamic mechanical analysis (DMA) apparatus to determine the complex viscoelastic functions. The DMA and nanoindentation results were compared and found in a good agreement, indicating the validity of the new method presented.