Update this copy and transpose macro?

Coyotex3

Well-known Member
Joined
Dec 12, 2021
Messages
507
Office Version
  1. 365
Platform
  1. Windows
Hey guys, So I have data in this format

Order Template.xlsx
ABCDEFGHIJKLMNOP
1CityOrder RecipientPrimary AddressSecondary AddressCity, State, Zip CodePrimary OrderSecondary OrderThird OrderAdditional OrderAmount(1)Amount(2)Amount(3)BirthdayAccount Type
2New YorkJohn Doe 1123 Make it Happen150 We Did ItManhattan, NY, 1000112545545687585463210100754610001/10/1950Premier
3New YorkJohn Doe 2124 Make it Happen151 We Did ItManhattan, NY, 10002125465456975854632111000754710001/10/1950Preferred
4New YorkJohn Doe 3125 Make it Happen152 We Did ItManhattan, NY, 1000312547545707585463212150754810001/10/1950Preferred
5New YorkJohn Doe 4126 Make it HappenManhattan, NY, 10004125485457175854632132000754910001/10/1950Preferred
6New YorkJohn Doe 5127 Make it HappenManhattan, NY, 100051254954572758545000755010001/10/1950Preferred
7New YorkJohn Doe 6128 Make it HappenManhattan, NY, 100061255054573758545000755110001/10/1950Preferred
8New YorkJohn Doe 7129 Make it HappenManhattan, NY, 10007125515457475854546556000755210001/10/1950Preferred
9New YorkJohn Doe 8130 Make it HappenManhattan, NY, 100081255254575758546465467000755310001/10/1950Preferred
10New YorkJohn Doe 9131 Make it HappenManhattan, NY, 10009125535457675854654657000755410001/10/1950Preferred
11
12
13
Sheet1


Ideally I would like to copy paste transpose some data on a loop in order to create a new sheet and autofill the information like this.

Order Template.xlsx
ABCDEFG
1Order Form
2TODAY'S DATE:1/10/2021
3DATE NEEDED:1/11/2021
4Order Type
5Point of Contact:John Doe 1
6Total Due1,000
7Order Recipient:
8Primary Address123 Make it Happen
9Secondary Address150 We Did It
10City, State, Zip CodeManhattan, NY, 10001
11Additional Information
12Seller:
13Primary Order12545Amount(1)$100.00
14Secondary Order54568Amount(2)$7,546.00
15Third Order75854Amount(3)$1,000.00
16Additional Order63210Amount(4)
17Description:
18Signature:
19Manager Print:
20Signature:
21Date:
22
23Reason
24
25
26
27
28
29
30
31
32
33
34
Sheet2


The macro that I have(obtained from here but altered) was this
VBA Code:
Sub CopyPasteTranspose()

    Dim i As Long
    With Sheets("Sheet1")
        For i = 2 To .Range("A" & Rows.Count).End(3).Row
            Sheets("sheet2").Copy After:=Sheets(Sheets.Count)
            ActiveSheet.Name = "Order" & i - 5
            ActiveSheet.Range("C9").Resize(12).Value = Application.Transpose(.Range("B" & i).Resize(, 12).Value)
        Next
    End With
End Sub

That code was for a totally different format and I do not know how to alter it further. Ideally I would also like for cell "B2" to = Today's date and "C2" Date + 1.

Thank you guys!!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
For the format you have in sheet2, try the following:

VBA Code:
Sub CopyAndTranspose()
  Dim sh1 As Worksheet, sh3 As Worksheet
  Dim i As Long
  
  Set sh1 = Sheets("Sheet1")
  For i = 2 To sh1.Range("A" & Rows.Count).End(3).Row
    Sheets("Sheet2").Copy after:=Sheets(Sheets.Count)
    Set sh3 = ActiveSheet
    sh3.Name = "Order " & sh1.Range("F" & i).Value
    sh3.Range("B2").Value = Date
    sh3.Range("B3").Value = Date + 1
    'Order Form
    sh3.Range("B4").Value = ""                        'order type
    sh3.Range("B5").Value = sh1.Range("B" & i).Value  'contact
    sh3.Range("B6").Value = ""                        'total due
    sh3.Range("B7").Value = sh1.Range("B" & i).Value  'recipient
    sh3.Range("B8").Value = sh1.Range("C" & i).Value  'prim add
    sh3.Range("B9").Value = sh1.Range("D" & i).Value  'sec add
    sh3.Range("B10").Value = sh1.Range("E" & i).Value 'city
    'Additional info
    sh3.Range("B13").Value = sh1.Range("F" & i).Value 'pri order
    sh3.Range("B14").Value = sh1.Range("G" & i).Value 'sec order
    sh3.Range("B15").Value = sh1.Range("H" & i).Value 'thi order
    sh3.Range("B16").Value = sh1.Range("I" & i).Value 'add order
    sh3.Range("D13").Value = sh1.Range("J" & i).Value 'amount 1
    sh3.Range("D14").Value = sh1.Range("K" & i).Value 'amount 2
    sh3.Range("D15").Value = sh1.Range("L" & i).Value 'amount 3
    sh3.Range("D16").Value = sh1.Range("M" & i).Value 'amount 4
  Next
End Sub
 
Upvote 0
Solution
For the format you have in sheet2, try the following:

VBA Code:
Sub CopyAndTranspose()
  Dim sh1 As Worksheet, sh3 As Worksheet
  Dim i As Long
 
  Set sh1 = Sheets("Sheet1")
  For i = 2 To sh1.Range("A" & Rows.Count).End(3).Row
    Sheets("Sheet2").Copy after:=Sheets(Sheets.Count)
    Set sh3 = ActiveSheet
    sh3.Name = "Order " & sh1.Range("F" & i).Value
    sh3.Range("B2").Value = Date
    sh3.Range("B3").Value = Date + 1
    'Order Form
    sh3.Range("B4").Value = ""                        'order type
    sh3.Range("B5").Value = sh1.Range("B" & i).Value  'contact
    sh3.Range("B6").Value = ""                        'total due
    sh3.Range("B7").Value = sh1.Range("B" & i).Value  'recipient
    sh3.Range("B8").Value = sh1.Range("C" & i).Value  'prim add
    sh3.Range("B9").Value = sh1.Range("D" & i).Value  'sec add
    sh3.Range("B10").Value = sh1.Range("E" & i).Value 'city
    'Additional info
    sh3.Range("B13").Value = sh1.Range("F" & i).Value 'pri order
    sh3.Range("B14").Value = sh1.Range("G" & i).Value 'sec order
    sh3.Range("B15").Value = sh1.Range("H" & i).Value 'thi order
    sh3.Range("B16").Value = sh1.Range("I" & i).Value 'add order
    sh3.Range("D13").Value = sh1.Range("J" & i).Value 'amount 1
    sh3.Range("D14").Value = sh1.Range("K" & i).Value 'amount 2
    sh3.Range("D15").Value = sh1.Range("L" & i).Value 'amount 3
    sh3.Range("D16").Value = sh1.Range("M" & i).Value 'amount 4
  Next
End Sub
You are an absolute god amongst men!!!

Tu eres mi heroe!
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
Aprecio tus comentarios ;)
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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