Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Auto copy and insert a defined number of rows as defined in a cell

Hi
I don't know much about VBA but could probably work something out.
I need to produce carton labels from a spreadsheet using Word to mail merge
and the labels need to include 1 of 10, 2 of 10 on them. The number of
labels required is dependant on a number which is included for each row of
data in the spreadsheet. What I am doing at the moment is copying each row
and insert pasting the additional number of rows required. In the new rows I
then add 1 of 10 in the first row, 2 of 10 in the second row etc. etc. This
then enables me to perform the mailmerge.
I have around 300 label variants (300 different rows of data) which yield
around 2500 labels and I have to do this every 3 weeks. As you can imagine
it takes a crazy amount of time and requires a lot of checking.
I'd guess there must be a much easier way that even someone of my moderate
experience could execute but I need a few pointers to get me started.
Any advice greatly appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Auto copy and insert a defined number of rows as defined in a cell

Sub InsertRows()
'assumes column A contains the total number of rows required for each
'row of data
'assumes this cell can be overwritten with "1 of n"
'A3 taken as the first cell containing data
'assumes Sheet1 contains the data

'turn off screen updating for speed
Application.ScreenUpdating = False

'initialize variables
Dim rngEndcell As Range 'last occupied cell in column A
Dim rngInsrt As Range 'range of occupied cells in Column A
Dim L As Long 'number of rows to be inserted
Dim i As Long 'loop variable
Dim S As Long 'loop variable
Dim v As Long 'loop variable
Dim T As Range 'transient address of cell below which rows are
added

'get address of last occupied cell in column A
Set rngEndcell = Sheets("sheet1").Cells(Rows.Count, "A").End(xlUp)
'set the occupied range
Set rngInsrt = Range("A3", rngEndcell)
'initialise a loop variable with the number of rows
i = rngInsrt.Rows.Count

'step through the range from the bottom up
For S = i To 1 Step -1

'T holds the address of the cell below which rows are inserted
Set T = Range("A3").Offset(S - 1, 0)
'L holds the total number of rows required
L = Range("A3").Offset(S - 1, 0).Value

T = "1 of " & L
'perform the loop inserting rows and
'copying the initial row and setting the "1 of n" value
For v = 1 To L - 1
T.Offset(v, 0).EntireRow.Insert shift:=xlDown
T.EntireRow.Copy
T.Offset(v, 0).EntireRow.PasteSpecial xlPasteValuesAndNumberFormats
T.Offset(v, 0) = v + 1 & " of " & L
Next v

Next S

'get rid of crawling ants
Application.CutCopyMode = False

'select a finishing location for the cursor
Sheets("sheet1").Range("A1").Select

Application.ScreenUpdating = True

End Sub



"Billy" wrote in message
...
Hi
I don't know much about VBA but could probably work something out.
I need a few pointers to get me started.
Any advice greatly appreciated.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fill each time one cell/row with a specific number,for defined col nerohnze Excel Programming 1 October 4th 07 12:59 PM
Insert a cell into a defined place (or bookmark) in a word doc raphiel2063 Excel Programming 1 September 7th 07 01:45 PM
Insert Row by a defined Number comotoman Excel Discussion (Misc queries) 4 October 11th 05 09:50 PM
auto deleting defined rows LoriM Excel Discussion (Misc queries) 4 August 4th 05 06:20 PM
Application-defined or object-defined error on copy Josh Sale Excel Programming 1 February 3rd 05 01:40 AM


All times are GMT +1. The time now is 12:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"