Without seeing the code, I can’t be 100% sure, but I suspect that you were faced with a specific problem that I made when I tried to reuse the current partition function with the new partition scheme. My partition function defined 16 range values, however my partition scheme only defined 8 partitions, which led to the same error you indicated.
In my case, the solution was simply not to try to reuse the existing partition function, but instead create a new partition function and partition scheme with an equal number of range values and partitions as follows:
CREATE PARTITION FUNCTION partitionFunctionName (datetime)
( '20130228 23: 59: 59,997',
'20130331 23: 59: 59,997',
'20130430 23: 59: 59,997',
'20130531 23: 59: 59,997',
'20130630 23: 59: 59,997',
'20130731 23: 59: 59,997',
'20130831 23: 59: 59,997',
'20130930 23: 59: 59,997'
)
GO
[partitionSchemeName]
PARTITION partitionFunctionName TO ( [PartitioningFileGroupName1] , [PartitioningFileGroupName2] , [PartitioningFileGroupName3] , [PartitioningFileGroupName4] , [PartitioningFileGroupName5] , [PartitioningFileGroupName6] , [PartitioningFileGroupName7] , [PartitioningFileGroupName8] , [] )
, , , , - !