Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-02-2018, 08:09 AM
josbor01 josbor01 is offline creating multiple data rows, for labels based on a cell value Windows 10 creating multiple data rows, for labels based on a cell value Office 2016
Novice
creating multiple data rows, for labels based on a cell value
 
Join Date: Jan 2018
Posts: 2
josbor01 is on a distinguished road
Default creating multiple data rows, for labels based on a cell value

I have a need to produce multiple labels (probably via a mail merge (or something). my sticking point is that the number of labels will vary based on a cell value for the given row(i.e quantity)


I am assuming there is a way within a loop or some other method, but I am not finding such an example in my searches. currently, all of the data is in Excel-but could export to Access if a solution within Access is needed for more in-depth code
Sample data below with some explanation

item quantity # of labels needed( quantity*2)
101 1 2
102 5 10
Reply With Quote
  #2  
Old 01-02-2018, 08:51 AM
NoSparks NoSparks is offline creating multiple data rows, for labels based on a cell value Windows 7 64bit creating multiple data rows, for labels based on a cell value Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Assuming items start in A2 with quantity in column B,
you could produce a list of all the labels needed in another column for mail merge (or something.)
Code:
Sub test_1()
    Dim rng As Range, cl As Range
    Dim i As Integer, wr As Long  '<~~ wr is write row

With Sheets("Sheet1")  '<~~ change sheet name to suit
    Set rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
    wr = 2  '<~~ row to start writing on
    For Each cl In rng
        For i = 1 To cl.Offset(, 1).Value * 2
            .Cells(wr, 5).Value = cl.Value  '<~~ column E is 5
            wr = wr + 1
        Next i
    Next cl
End With
End Sub
Reply With Quote
  #3  
Old 01-02-2018, 10:59 AM
josbor01 josbor01 is offline creating multiple data rows, for labels based on a cell value Windows 10 creating multiple data rows, for labels based on a cell value Office 2016
Novice
creating multiple data rows, for labels based on a cell value
 
Join Date: Jan 2018
Posts: 2
josbor01 is on a distinguished road
Default little more info

Thanks, that helps; but of course, need a little more help with the range and to pull out specific columns. I have provided additional columns and data elements

input data: {sheetX}
Item{A} Description{B} data1{D} data2{G} quantity{J} Loc1{K} loc2{L}
101 Description101 data101_1 data101_2 1 M1 C1
102 Description102 data102_1 data102_2 2 M1 C2

needed/expected output: {label_data}
Item{A} Description{B} data1{C} data2{D} quantity{E} Loc1{F} loc2{G}
101 Description101 data101_1 data101_2 1 M1 C1
101 Description101 data101_1 data101_2 1 M1 C1
102 Description102 data102_1 data102_2 2 M1 C2
102 Description102 data102_1 data102_2 2 M1 C2
102 Description102 data102_1 data102_2 2 M1 C2
102 Description102 data102_1 data102_2 2 M1 C2
Reply With Quote
  #4  
Old 01-02-2018, 02:04 PM
NoSparks NoSparks is offline creating multiple data rows, for labels based on a cell value Windows 7 64bit creating multiple data rows, for labels based on a cell value Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 831
NoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really niceNoSparks is just really nice
Default

Code:
Sub SecondLocationOfGoalPosts()

Dim rng As Range, cl As Range
Dim wr As Long, i As Integer

Set rng = Sheets("sheetx").Range("A2", Sheets("sheetx").Range("A" & Rows.Count).End(xlUp))
wr = 2

With Sheets("label_data")
    For Each cl In rng
        For i = 1 To cl.Offset(, 9).Value * 2
            .Cells(wr, 1) = cl
            .Cells(wr, 2) = cl.Offset(, 1)
            .Cells(wr, 3) = cl.Offset(, 3)
            .Cells(wr, 4) = cl.Offset(, 6)
            .Cells(wr, 5) = cl.Offset(, 9)
            .Cells(wr, 6) = cl.Offset(, 10)
            .Cells(wr, 7) = cl.Offset(, 11)
            wr = wr + 1
        Next i
    Next cl
End With

End Sub
Reply With Quote
Reply

Tags
adding multiple rows, mail merge, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting multiple words from one cell into individual rows while copying all other data randyaserve Excel Programming 4 10-05-2015 09:52 AM
Hide rows in multiple columns based on zero values Deane Excel Programming 19 06-23-2015 11:24 PM
creating multiple data rows, for labels based on a cell value Insert values from multiple rows based on value in one column pachmarhi Excel 3 07-18-2014 09:57 PM
creating multiple data rows, for labels based on a cell value Creating formula based on if data is correct in cell MattMurdock Excel 1 08-06-2012 03:11 AM
creating multiple data rows, for labels based on a cell value Hide Rows and Update Chart based on cell value ubns Excel Programming 5 05-07-2012 05:44 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft