Visual Basic command to write sequence

  • Thread starter Thread starter melawaisi
  • Start date Start date
M

melawaisi

HI,


i would like to write a command in visual basic control so that when i
click on a button,

it takes the value of sequences I would like to generate from lets say
B2, and then print in Row C No1 9 times and then No2 9 times, so if I
had 9 in b2 then it will print no1, then 2 then 3….


Thanks.
 
How do you know when to quit?

9 no1's, 9 no2's, ..., 9 no#'s????

I think this'll work:

Option Explicit
Sub testme01()

Dim RepeatNumber As Long
Dim howMany As Long
Dim iCtr As Long

howMany = CLng(Application.InputBox("Stop at no1, no2, no3,....?", _
Title:="Stop with", Default:=6, Type:=1))
If howMany = 0 Then
Exit Sub
End If

With ActiveSheet
.Range("c:c").ClearContents 'wipe out previous????
If IsNumeric(.Range("B1").Value) Then
RepeatNumber = CLng(.Range("b1").Value)
If RepeatNumber > 0 Then
For iCtr = 1 To howMany
.Cells(1, "C").Offset((iCtr - 1) * RepeatNumber) _
.Resize(RepeatNumber, 1).Value = "No" & iCtr
Next iCtr
End If
End If
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top