View Single Post
 
Old 10-18-2014, 11:46 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I'm assuming you have some other code that loops through the rows and all you're after is the basic logic for working out the #s to populate the 'spread' range. The following code shows how to do that, taking a value entered in an InputBox as the # to spread and the selected range as the cells over which the spreading is to be done:
Code:
Sub Demo()
Dim i As Long, j As Long, k As Long, l As Long, x As Long
i = CLng(InputBox("Number to spread?", , 0))
j = Selection.Cells.Count
k = -Int(-i / j)
l = k * j - i
For x = 1 To l
  Selection.Cells(x).Value = k - 1
Next
For x = l + 1 To j
  Selection.Cells(x).Value = k
Next
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote