View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Bruce Sinclair Bruce Sinclair is offline
external usenet poster
 
Posts: 169
Default Is there a simple way to generate patterns of numbers in XL ?

In article , "Jim Cone" wrote:
Here is some quickie VBA code that worked a few times.
Select the cells that receive the numbers and run the code...


Thanks Jim. I will give that a go ... but I should say that part of what I'm
trying to avoid by using the minitab method is selecting cells (with only 32
x 72, I'm already at <quickly checks ... 2304 lines. :)
Hmmm ... a thought. Selecting a range of cells is relatively easy in VBA
isn't it ? I could add a 'select range' function just after the start
number/repeat number input, yes ? Then it would be self contained and much
more useful. :)

Thanks again.

'---
Sub FillErUp()
'Jim Cone - March 2010
Dim sRng As Range
Dim startNum As Variant
Dim repeatNum As Variant
Dim N As Long

startNum = InputBox("Fill in Start Number.", "Easy Does It", "1")
If LenB(startNum) = 0 Then Exit Sub
repeatNum = InputBox("Fill in Repeat Number.", "Easy Does It", "5")
If LenB(repeatNum) = 0 Then Exit Sub

Set sRng = Selection.Columns(1).Cells
If sRng.Count < repeatNum Then
MsgBox "Not enough cells selected. ", vbExclamation, "Hard To Do It"
Exit Sub
End If
Application.ScreenUpdating = False
For N = 1 To sRng.Count
sRng(N).Value = startNum
If N Mod repeatNum = 0 Then
startNum = startNum + 1
End If
Next
Application.ScreenUpdating = True
End Sub