Recurring String Generator

dlo1503

New Member
Joined
Feb 24, 2020
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hello

I am currently writing a code to generate labels from a spreadsheet of data. At the minute the various strings are made up from cells in Row 2 on Sheet1. I would like this to continue down until the last row of text in Column B. The output looks like I want it to however I would like it to generate output for each row in column B on Sheet 1 to each row in Column A on Sheet2.

Sub Concatenate2()

Dim String1 As String
Dim String2 As String
Dim String3 As String
Dim String4 As String
Dim String5 As String
Dim String 6 As String

Dim full_string As String

String1 = Sheet1.Cells(2, 20).Value
String2 = Sheet1.Cells(2, 2).Value
String3 = Sheet1.Cells(2, 4).Value
String4 = Sheet1.Cells(2, 6).Value
String5 = Sheet1.Cells(2, 5).Value
String6 = Sheet1.Cells(2, 15).Value

Sheet2.Cells(1, 1).Value = String1 & vbNewLine & vbNewLine & String2 & vbNewLine & "QTY- " & String3 & vbNewLine & String4 & "mm " & String5 & vbNewLine & String6

End Sub


Any help greatly appreciated

thanks
Daniel
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
How about
VBA Code:
Sub dlo()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long
   
   With Sheets("Sheet1")
      Ary = .Range("B2:T" & .Range("B" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To 1)
   For r = 1 To UBound(Ary)
      Nary(r, 1) = Ary(r, 1) & vbLf & vbLf & Ary(r, 1) & vbLf & "QTY- " & Ary(r, 3) & vbLf & Ary(r, 5) & "mm " & Ary(r, 4) & vbLf & Ary(r, 14)
   Next r
   Sheets("Sheet2").Range("A2").Resize(r - 1).Value = Nary
End Sub
 
Upvote 0
Hi Fluff

thank you for your speedy response. Appreciate that so much. My only issue with this is String1 was to remain an constant throughout. I should have mentioned that. It represents an order number that will apply to all of the labels.

Can you help me with an amendment please?

Thanks
Daniel
 
Upvote 0
So each line should start with the value in T2 & all other strings are from the individual rows?
 
Upvote 0
Yes that's correct. T2 should appear at the top of each and then every row from row 2 onwards

Thanks
Daniel
 
Upvote 0
Ok, how about
VBA Code:
Sub dlo()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long
   
   With Sheets("Sheet1")
      Ary = .Range("B2:T" & .Range("B" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Ary), 1 To 1)
   For r = 1 To UBound(Ary)
      Nary(r, 1) = Ary(1, 19) & vbLf & vbLf & Ary(r, 1) & vbLf & "QTY- " & Ary(r, 3) & vbLf & Ary(r, 5) & "mm " & Ary(r, 4) & vbLf & Ary(r, 14)
   Next r
   Sheets("Sheet2").Range("A2").Resize(r - 1).Value = Nary
End Sub
 
Upvote 0
That is perfect Fluff. Works a charm.

You're a star!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
Fluff, can I pester you with one more thing as you are an Excel Wizard. This code is basically to create a label without having to involve Word. I need to include a QR code in with the text that is a representation of the output the code has generated. Any ideas about this? I've been trawling forums for hours trying to find a solution but can't get anywhere?

Much appreciated
Daniel
 
Upvote 0
Absolutely no idea, I know nothing about QR codes.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top