How can I get to VBA code that copies values & pastes them into a tblStaging, pastes those values into a tblTarget, & appends the tblTarget thereafter

I have values in a work report that need to essentially get copy & pasted into tblStaging & tblTarget, and allow for the same thereafter. So, e.g., a team “Ravens” and city “Baltimore” from report “Report Type 1” has values in a table on the work report that need to be C&P’d into a table that will then be used as a staging table to paste the now-formatted values into a target table. This has to be done for multiple teams, locations, and report types, so clearing and reusing the stage tables is necessary. The end result should be a target table that houses all the data that is now pivoted from the work report.

Attached are images of the desired stepthrough and results.Steps 1-6, Step 6.5,Step 7,Step 8

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Sub Example_1()
Dim sourceWorkbook As Workbook
Dim sourceWorksheet As Worksheet
Dim targetWorkbook As Workbook
Dim targetWorksheet As Worksheet
Dim k As Long
Set targetWorkbook = Workbooks("Learn VBA")
Set targetWorksheet = targetWorkbook.Sheets("Target Worksheet")
Set sourceWorksheet = targetWorkbook.Sheets("Source Worksheet")
targetWorkbook.Sheets("Source Worksheet").Activate
Range("B6").Select
Range(Selection, Selection.End(xlToRight)).Copy
Range("V6").PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.CutCopyMode = False
Range("B7").Select
Range(Selection, Selection.End(xlToRight)).Copy
'Im wanting to select the cell after (below) the final cell in col v so I
'can append the table with the cells copied from B7 and to the right.
'Then I need this done for every row and to the right for B8:B10
Range("V6").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Offset(1, 0).Range("A1").PasteSpecial xlPasteValues, Transpose:=True
'I think something along the lines of:
For i = 7 To 10
Range("B" & i).Select
Range(Selection, Selection.End(xlToRight)).Copy
'Range("V", count rows + 1) pastevalues transpose:=True
'Range("B8", Selection.End(xlToRight)).Copy
'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True
'Range("B9", Selection.End(xlToRight)).Copy
'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True
'Range("B10", Selection.End(xlToRight)).Copy
'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True
'Here, I want to copy the value in cell B1 and paste it to the entire col R, after the first
'cells are pasted values and transposed - see desired outcome
Range("B1").Copy
Range("R6", Selection.End(xlDown)).PasteSpecial xlPasteValues
Range("B2").Copy
Range("S6", Selection.End(xlDown)).PasteSpecial xlPasteValues
Range("B3").Copy
Range("Q6", Selection.End(xlDown)).PasteSpecial xlPasteValues
'How can I count the number of non-empty cells in Range("B6:M6"), then select that count
'of cells from the col "X6", and paste it for each instance that a row was copied in the
'tblStaging[Staging Table 4 (Period)]? - see desired outcome
'There is a formula that should continue down the column U:
'=XLOOKUP([@Period],tblPeriods[Period],tblPeriods[Date],"")
'Then, I want to take the now complete table tblStaging ("Q6:V40") copy and paste values
'to the target table tblTarget on the Target Worksheet tab
Range("Q6:V40").Copy
targetWorkbook.Sheets("Target Worksheet").Activate
Range("A2").PasteSpecial xlPasteValues
'Finally, I want to clear the tables "Q6:V40" and "B6:M10" so new data can be used
'I want to be able to do this for every new instance of Items 1, 2, and 3
'e.g., now, Item 1 = Cincinnati, Item 2 = Bengals, Item 3 = Report Type 2
'and new values that will be pasted into the rows x columns table ("B6:M10")
End Sub
</code>
<code>Sub Example_1() Dim sourceWorkbook As Workbook Dim sourceWorksheet As Worksheet Dim targetWorkbook As Workbook Dim targetWorksheet As Worksheet Dim k As Long Set targetWorkbook = Workbooks("Learn VBA") Set targetWorksheet = targetWorkbook.Sheets("Target Worksheet") Set sourceWorksheet = targetWorkbook.Sheets("Source Worksheet") targetWorkbook.Sheets("Source Worksheet").Activate Range("B6").Select Range(Selection, Selection.End(xlToRight)).Copy Range("V6").PasteSpecial Paste:=xlPasteValues, Transpose:=True Application.CutCopyMode = False Range("B7").Select Range(Selection, Selection.End(xlToRight)).Copy 'Im wanting to select the cell after (below) the final cell in col v so I 'can append the table with the cells copied from B7 and to the right. 'Then I need this done for every row and to the right for B8:B10 Range("V6").Select Range(Selection, Selection.End(xlDown)).Select ActiveCell.Offset(1, 0).Range("A1").PasteSpecial xlPasteValues, Transpose:=True 'I think something along the lines of: For i = 7 To 10 Range("B" & i).Select Range(Selection, Selection.End(xlToRight)).Copy 'Range("V", count rows + 1) pastevalues transpose:=True 'Range("B8", Selection.End(xlToRight)).Copy 'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True 'Range("B9", Selection.End(xlToRight)).Copy 'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True 'Range("B10", Selection.End(xlToRight)).Copy 'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True 'Here, I want to copy the value in cell B1 and paste it to the entire col R, after the first 'cells are pasted values and transposed - see desired outcome Range("B1").Copy Range("R6", Selection.End(xlDown)).PasteSpecial xlPasteValues Range("B2").Copy Range("S6", Selection.End(xlDown)).PasteSpecial xlPasteValues Range("B3").Copy Range("Q6", Selection.End(xlDown)).PasteSpecial xlPasteValues 'How can I count the number of non-empty cells in Range("B6:M6"), then select that count 'of cells from the col "X6", and paste it for each instance that a row was copied in the 'tblStaging[Staging Table 4 (Period)]? - see desired outcome 'There is a formula that should continue down the column U: '=XLOOKUP([@Period],tblPeriods[Period],tblPeriods[Date],"") 'Then, I want to take the now complete table tblStaging ("Q6:V40") copy and paste values 'to the target table tblTarget on the Target Worksheet tab Range("Q6:V40").Copy targetWorkbook.Sheets("Target Worksheet").Activate Range("A2").PasteSpecial xlPasteValues 'Finally, I want to clear the tables "Q6:V40" and "B6:M10" so new data can be used 'I want to be able to do this for every new instance of Items 1, 2, and 3 'e.g., now, Item 1 = Cincinnati, Item 2 = Bengals, Item 3 = Report Type 2 'and new values that will be pasted into the rows x columns table ("B6:M10") End Sub </code>
Sub Example_1()

Dim sourceWorkbook As Workbook
Dim sourceWorksheet As Worksheet
Dim targetWorkbook As Workbook
Dim targetWorksheet As Worksheet
Dim k As Long

Set targetWorkbook = Workbooks("Learn VBA")
Set targetWorksheet = targetWorkbook.Sheets("Target Worksheet")
Set sourceWorksheet = targetWorkbook.Sheets("Source Worksheet")

targetWorkbook.Sheets("Source Worksheet").Activate
Range("B6").Select
Range(Selection, Selection.End(xlToRight)).Copy
Range("V6").PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.CutCopyMode = False

Range("B7").Select
Range(Selection, Selection.End(xlToRight)).Copy
'Im wanting to select the cell after (below) the final cell in col v so I
'can append the table with the cells copied from B7 and to the right.
'Then I need this done for every row and to the right for B8:B10
Range("V6").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Offset(1, 0).Range("A1").PasteSpecial xlPasteValues, Transpose:=True
'I think something along the lines of:
For i = 7 To 10
Range("B" & i).Select
Range(Selection, Selection.End(xlToRight)).Copy
'Range("V", count rows + 1) pastevalues transpose:=True

'Range("B8", Selection.End(xlToRight)).Copy
'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True
'Range("B9", Selection.End(xlToRight)).Copy
'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True
'Range("B10", Selection.End(xlToRight)).Copy
'Range("V6", Selection.End(xlDown)).Offset(1, 0).PasteSpecial xlPasteValues, Transpose:=True

'Here, I want to copy the value in cell B1 and paste it to the entire col R, after the first
'cells are pasted values and transposed - see desired outcome
Range("B1").Copy
Range("R6", Selection.End(xlDown)).PasteSpecial xlPasteValues
Range("B2").Copy
Range("S6", Selection.End(xlDown)).PasteSpecial xlPasteValues
Range("B3").Copy
Range("Q6", Selection.End(xlDown)).PasteSpecial xlPasteValues

'How can I count the number of non-empty cells in Range("B6:M6"), then select that count
'of cells from the col "X6", and paste it for each instance that a row was copied in the
'tblStaging[Staging Table 4 (Period)]? - see desired outcome

'There is a formula that should continue down the column U:
'=XLOOKUP([@Period],tblPeriods[Period],tblPeriods[Date],"")

'Then, I want to take the now complete table tblStaging ("Q6:V40") copy and paste values
'to the target table tblTarget on the Target Worksheet tab

Range("Q6:V40").Copy
targetWorkbook.Sheets("Target Worksheet").Activate
Range("A2").PasteSpecial xlPasteValues

'Finally, I want to clear the tables "Q6:V40" and "B6:M10" so new data can be used
'I want to be able to do this for every new instance of Items 1, 2, and 3
'e.g., now, Item 1 = Cincinnati, Item 2 = Bengals, Item 3 = Report Type 2
'and new values that will be pasted into the rows x columns table ("B6:M10")

End Sub

New contributor

Jared Carbo is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật