The sum of the digits 1 through 9 is 45.
This set appears 201 times in the units position, between 1 and 2009 inclusive, contributing 201*45=9045 to the total. A single 1 through 4 each, then adds a total of 10 more to the contributions made by the units position, making 9055 the overall contribution of the units position.
The 1 through 9 set appears 200 times, from 10 through 1999, making 9000, and there are 5 more from the 1's in 2010 through 2014 that are in the 10's position, adding up to 9005 overall from the tens position.
The hundreds position contributes only the 9000 from the 200 occurrences in that position
The digit 1 occurs 1000 times in the thousands position and the digit 2 occurs 15 times, adding 30, making 1030 the total contribution of the thousands position.
28090 the answer.
And also of course as a check:
Dim crlf$, used(9), bypos(4)
Function mform$(x, t$)
a$ = Format$(x, t$)
If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
mform$ = a$
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
For i = 1 To 2014
tot = tot + sod(i)
Text1.Text = Str(tot) + crlf
For i = 0 To 3
Text1.Text = Text1.Text & Str(bypos(i))
s$ = LTrim(Str(n))
tot = 0
For i = 1 To Len(s$)
tot = tot + Val(Mid(s$, i, 1))
bypos(Len(s$) - i) = bypos(Len(s$) - i) + Val(Mid(s$, i, 1))
sod = tot
9055 9005 9000 1030
showing first the total, and then categorized by position:
thousands, hundreds, tens, units.