Macro that will Copy, Create, Paste data from a table on a loop.

Coyotex3

Well-known Member
Joined
Dec 12, 2021
Messages
507
Office Version
  1. 365
Platform
  1. Windows
Hello I have The following information

Book2.xlsx
ABCDEFGHIJKL
1Check Request Format
2
3Date Requested
4Approved By
5
6
7
8
9Name
10Address
11Phone Number
12Amount
13Email Address
14
15Signature
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Sheet2


Book2.xlsx
ABCDEF
1Date RequestedDec-21
2Approved ByJohn Doe
3
4
5ChecksNameAddressPhone NumberAmountEmail Address
61James Band123 American Eagle111-111-1111$ 1,000,000.00JamesBand 123 American Eagle
72Williams Will124 American Eagle111-111-1112$ 1,000,000.00WilliamsWill 124 American Eagle
83Mighty Mac125 American Eagle111-111-1113$ 1,000,000.00MightyMac 125 American Eagle
94Rapid Lightning126 American Eagle111-111-1114$ 1,000,000.00RapidLightning 126 American Eagle
105Vanishing Cloud127 American Eagle111-111-1115$ 1,000,000.00VanishingCloud 127 American Eagle
116Stalking Wolf128 American Eagle111-111-1116$ 1,000,000.00StalkingWolf 128 American Eagle
127Swimming Bird129 American Eagle111-111-1117$ 1,000,000.00SwimmingBird 129 American Eagle
138Sweet Home Alabama130 American Eagle111-111-1118$ 1,000,000.00SweetHomeAlabama 130 American Eagle
14
15
16
17
18
19
20
Sheet1


What I would like to do is to be able to copy sheet2 and paste it as "Check1." Then I want Excel to go to the second table(Sheet1) and copy ("B6:F6") and to PasteSpecial Transpose:=True into Worksheet("Check1") Range("C9").

Next step would be to once again copy Sheet2 and paste it as "Check2" this time. Then to go back to Sheet1 and this time copy("C7:F7") and PasteSpecial Transpose:=True into Worksheet("Check2") Range("C9") and so forth.

I would like for the code to do this until the end of the table on sheet two which may vary in length depending on the day.

Here is the code I had

VBA Code:
Sub CopySheet()

    Worksheets("Sheet2").Copy After:=Worksheets("Sheet2")
    ActiveSheet.Name = "Check1"
    Worksheets("Sheet1").Range("B6:F6").Copy
    Worksheets("Check1").Range("C9").PasteSpecial Transpose:=True
    Worksheets("Sheet2").Copy After:=Worksheets("Check1")
    ActiveSheet.Name = "Check2"
    Worksheets("Sheet1").Range("B7:F7").Copy
    Worksheets("Check2").Range("C9").PasteSpecial Transpose:=True
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try this:

VBA Code:
Sub CopySheet()
  Dim i As Long
  With Sheets("Sheet1")
    For i = 6 To .Range("A" & Rows.Count).End(3).Row
      Sheets("Sheet2").Copy After:=Sheets(Sheets.Count)
      ActiveSheet.Name = "Check" & i - 5
      ActiveSheet.Range("C9").Resize(5).Value = Application.Transpose(.Range("B" & i).Resize(, 5).Value)
    Next
  End With
End Sub
 
Upvote 0
Solution
Try this:

VBA Code:
Sub CopySheet()
  Dim i As Long
  With Sheets("Sheet1")
    For i = 6 To .Range("A" & Rows.Count).End(3).Row
      Sheets("Sheet2").Copy After:=Sheets(Sheets.Count)
      ActiveSheet.Name = "Check" & i - 5
      ActiveSheet.Range("C9").Resize(5).Value = Application.Transpose(.Range("B" & i).Resize(, 5).Value)
    Next
  End With
End Sub
This absolutely works! Thank you!!
 
Upvote 0
Im glad to help you, thanks for the feedback.
Thank you for helping. This is the first step for this Macro and I will more than likely play around with it in order to try to expand on it. Hope you are around to help out then!
 
Upvote 0

Forum statistics

Threads
1,223,238
Messages
6,170,939
Members
452,368
Latest member
jayp2104

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