View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Automatically generating a specified number of new rows (records)

The following procedure reads the text in the active cell, adds the requisite
number of rows below it and then adds the labels to these rows. The text in
the active cell must be in the form of a numeric, a space and then text:

Sub MakeLabels()
Dim x As Integer, n As Integer
Dim c As Range
Dim t As String, tt As String

Set c = ActiveCell
c.Value = Trim(c.Value)
n = InStr(c.Value, " ")
t = Left(c.Value, n - 1)
tt = Right(c.Value, Len(c.Value) - n + 1)
If n = 0 Or Not IsNumeric(t) Then Exit Sub
n = CInt(t)
c(2).Resize(n).EntireRow.Insert
For x = 1 To n
c(x + 1) = x & " of " & n & tt
Next
End Sub

Regards,
Greg


"Lele" wrote:

I have very limited programming experience. Is there a simple way to create
code that would read the following row in my spreadsheet:

X apples

and then create the following new rows:
1 of X apples
2 of X apples
and so on.

I am trying to create inventory labels.
--
Lele