Dynamic Macro to copy and paste

ferr

New Member
Joined
Jun 9, 2022
Messages
24
Office Version
  1. 365
Platform
  1. Windows
I have 2 sheets, call it ‘upload’ and ‘final’.
There are calculations that are run behind the scenes I.e. other tabs that require Columns E:AN from the upload tab to be copied and pasted one at a time to the Final tab.
Need a macro, that essentially does this.
  1. Copies E56,E61,E66 from Upload tab and pastes in final tab by looking up the participants in column A and matching to the participants in the upload tab (B56,B61,B66) and the dates in row 1 and matching to the date in row 48 in the upload tab.
For example, E56,E61 and E66 will be pasted in F2,F3 and F4 in the final tab.
  1. The macro will then continue doing this so, it will copy the next 3 in the upload tab E57,E62,E67 and paste in the appropriate cells in the final tab until we get to the last column say AN.
The cells in the upload tab need to be filled up one at a time (3 participants at a time) for the calculations to work, hence why an INDEX MATCH won’t work as the numbers change once pasted.
Also needs to be dynamic, hence why it looks ups the participants and date before pasting as the dates or participants will change.
Thank you.

test macro.xlsx
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAVAWAXAYAZBABB
46Participants
47
48Row Labels11/30/202412/31/202401/31/202502/28/202503/31/202504/30/202505/31/202506/30/202507/31/202508/31/202509/30/202510/31/202511/30/202512/31/202501/31/202602/28/202603/31/202604/30/202605/31/202606/30/202607/31/202608/31/202609/30/202610/31/202611/30/202612/31/202601/31/202702/28/202703/31/202704/30/202705/31/202706/30/202707/31/202708/31/202709/30/202710/31/202711/30/202712/31/202701/31/202802/29/202803/31/202804/30/202805/31/202806/30/202807/31/202808/31/202809/30/202810/31/202811/30/202812/31/2028
49A9,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,859
50B5,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,444
51C6,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,555
52585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585########################585,858,585585,858,585
53
54A
55A
56A395,949,4954,696,9696,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,4644543354536,56546,46446,46446,46446,46446,4645,555433-
57
58
59B
60B
61B4,546,5676,76646,464817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,6833,422817,6833,4333,423817,683817,683817,6833,443343817,68334,343,434343--
62
63
64C
65C
66C7,676656,5658,877787878787878787878787878787878783,434,3434,343,4337878787878787878783,43334,343783,43478787878787834343,433-
Upload
Cell Formulas
RangeFormula
B54:B55,B64:B65,B59:B60B54=B55
B56B56=B49
B61B61=B50
B66B66=B51
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E65:AU65Expression=E$45=$E$45+2textNO
E65:AU65Expression=E$45=$E$45+1textNO
E65:AU65Expression=E$45=2025textNO
E55:AU55Expression=E$45=$E$45+2textNO
E55:AU55Expression=E$45=$E$45+1textNO
E55:AU55Expression=E$45=2025textNO
E46:N46,S46:AB46,AG46:AP46,AU46:BB46Cell Value=FALSEtextNO
E46:N46,S46:AB46,AG46:AP46,AU46:BB46Cell Value=TRUEtextNO



test macro.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAO
1ParticipantsJul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25Apr-25May-25Jun-25Jul-25Aug-25Sep-25Oct-25Nov-25Dec-25Jan-26Feb-26Mar-26Apr-26May-26Jun-26Jul-26Aug-26Sep-26Oct-26Nov-26Dec-26Jan-27Feb-27Mar-27Apr-27May-27Jun-27Jul-27Aug-27Sep-27Oct-27
2A8,787,878.0054,565,465.0067,676.006,676.00
3B6,767,678.0056,655.007,645,435.00754.00
4C34,434,343.00767,667.0054,544.009,548.00
5
6D6,767.004,545.00565,656,564.0076,764.00
7E4,545.006,767.007,676.004,354,544.00
8F----
9
10G8,599.00545,454.00454.004,545.00
11H545.00-94,394.00454.00
12II454.0076.00545,466,565.00-
13
14J4,532.004,545.004,545.00567,786.00
15K----
16L2,324,324.0054,545.0065,656,565.0067,657.00
17
18M----
19N7,676.005,656.00665,656.0056,565.00
20O---56,565.00
21---
22P----
23Q765,434.004,565,656.0056,567.006,565.00
24R----
25----
26S5,555.0022,466,777.00343,456.0075,665,565.00
27T55,567,676.004,554.0067,645,453.0056,565,643.00
28U----
29----
30V5,454.005,653.00-54,453.00
31W554,567.00898,989.0078,708.00434,345.00
32X424.003.0076,545.0056,677,667.00
33----
34Y43,243,435.00545.005,454.0022,323.00
35Z----
36AB15,454.00343.00-232.00
37----
38QC2-354,545.00543,342.00-
39DF4
40DG65.00545,454.0054.00544.00
Final
Cells with Conditional Formatting
CellConditionCell FormatStop If True
O2:AM38Cell Value<0textNO
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
1. Is there a more efficient code than the code below, as I have to run it for each participant group i.e. 10 times and VBA won't allow it because it is too long?
2. Instead of the code starting to paste in column H as the dates will change frequently, can it look up the date in the upload tab row 48 and match it to the date in the final tab row 1 before pasting?


VBA Code:
Sheets("UPLOAD").Select

    Range("G50").Select

    ActiveSheet.PivotTables("PivotTable7").PivotCache.Refresh

    Range("E56,E61,E66").Select

    Range("E66").Activate

    Selection.Copy

    Sheets("Final").Select

    Range("H2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("F56,F61,F66").Select

    Range("F66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("I2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("G56,G61,G66").Select

    Range("G66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("J2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("H56,H61,H66").Select

    Range("H66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("K2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("I56,I61,I66").Select

    Range("I66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("L2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("J56,J61,J66").Select

    Range("J66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("M2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("K56,K61,K66").Select

    Range("K66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("N2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("L56,L61,L66").Select

    Range("L66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("O2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("M56,M61,M66").Select

    Range("M66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("P2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

     Sheets("UPLOAD").Select

    Range("N56,N61,N66").Select

    Range("N66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("Q2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("O56,O61,O66").Select

    Range("O66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("R2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("P56,P61,P66").Select

    Range("P66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("S2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("Q56,Q61,Q66").Select

    Range("Q66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("T2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("R56,R61,R66").Select

    Range("R66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("U2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("S56,S61,S66").Select

    Range("S66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("V2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("T56,T61,T66").Select

    Range("T66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("W2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("U56,U61,U66").Select

    Range("U66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("X2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

       

        Sheets("UPLOAD").Select

    Range("V56,V61,V66").Select

    Range("V66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("Y2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("W56,W61,W66").Select

    Range("W66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("Z2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("X56,X61,X66").Select

    Range("X66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AA2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("Y56,Y61,Y66").Select

    Range("Y66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AB2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("Z56,Z61,Z66").Select

    Range("Z66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AC2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AA56,AA61,AA66").Select

    Range("AA66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AD2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AB56,AB61,AB66").Select

    Range("AB66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AE2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AC56,AC61,AC66").Select

    Range("AC66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AF2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

     Sheets("UPLOAD").Select

    Range("AD56,AD61,AD66").Select

    Range("AD66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AG2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AE56,AE61,AE66").Select

    Range("AE66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AH2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AF56,AF61,AF66").Select

    Range("AF66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AI2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AG56,AG61,AG66").Select

    Range("AG66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AJ2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AH56,AH61,AH66").Select

    Range("AH66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AK2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AI56,AI61,AI66").Select

    Range("AI66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AL2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AJ56,AJ61,AJ66").Select

    Range("AJ66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AM2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False

    Sheets("UPLOAD").Select

    Range("AK56,AK61,AK66").Select

    Range("AK66").Activate

    Application.CutCopyMode = False

    Selection.Copy

    Sheets("Final").Select

    Range("AN2").Select

    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

        :=False, Transpose:=False
 
Last edited by a moderator:
Upvote 0
1. Is there a more efficient code than the code below, as I have to run it for each participant group i.e. 10 times and VBA won't allow it because it is too long?
2. Instead of the code starting to paste in column H as the dates will change frequently, can it look up the date in the upload tab row 48 and match it to the date in the final tab row 1 before pasting?

VBA Code:
Sheets("UPLOAD").Select

Range("G50").Select

ActiveSheet.PivotTables("PivotTable7").PivotCache.Refresh

Range("E56,E61,E66").Select

Range("E66").Activate

Selection.Copy

Sheets("Final").Select

Range("H2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("F56,F61,F66").Select

Range("F66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("I2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("G56,G61,G66").Select

Range("G66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("J2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("H56,H61,H66").Select

Range("H66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("K2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("I56,I61,I66").Select

Range("I66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("L2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("J56,J61,J66").Select

Range("J66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("M2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("K56,K61,K66").Select

Range("K66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("N2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("L56,L61,L66").Select

Range("L66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("O2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("M56,M61,M66").Select

Range("M66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("P2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("N56,N61,N66").Select

Range("N66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("Q2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("O56,O61,O66").Select

Range("O66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("R2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("P56,P61,P66").Select

Range("P66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("S2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("Q56,Q61,Q66").Select

Range("Q66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("T2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("R56,R61,R66").Select

Range("R66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("U2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("S56,S61,S66").Select

Range("S66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("V2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("T56,T61,T66").Select

Range("T66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("W2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("U56,U61,U66").Select

Range("U66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("X2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False



Sheets("UPLOAD").Select

Range("V56,V61,V66").Select

Range("V66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("Y2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("W56,W61,W66").Select

Range("W66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("Z2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("X56,X61,X66").Select

Range("X66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AA2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("Y56,Y61,Y66").Select

Range("Y66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AB2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("Z56,Z61,Z66").Select

Range("Z66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AC2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AA56,AA61,AA66").Select

Range("AA66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AD2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AB56,AB61,AB66").Select

Range("AB66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AE2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AC56,AC61,AC66").Select

Range("AC66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AF2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AD56,AD61,AD66").Select

Range("AD66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AG2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AE56,AE61,AE66").Select

Range("AE66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AH2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AF56,AF61,AF66").Select

Range("AF66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AI2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AG56,AG61,AG66").Select

Range("AG66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AJ2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AH56,AH61,AH66").Select

Range("AH66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AK2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AI56,AI61,AI66").Select

Range("AI66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AL2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AJ56,AJ61,AJ66").Select

Range("AJ66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AM2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False

Sheets("UPLOAD").Select

Range("AK56,AK61,AK66").Select

Range("AK66").Activate

Application.CutCopyMode = False

Selection.Copy

Sheets("Final").Select

Range("AN2").Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _

:=False, Transpose:=False
 
Last edited by a moderator:
Upvote 0
VBA Code:
Sub TryThis()

    Dim rngCopy As Range
    Dim i As Long, inc As Long, NoSteps As Long
    
    Set rngCopy = Worksheets("Upload").Range("E56:AK56")
    NoSteps = 3     'It sounds like you need 10?
    inc = 5
    
    With Worksheets("Final").Range("H2:AN2")
        For i = 0 To NoSteps - 1
            .Offset(i).Value = rngCopy.Offset(i * inc).Value
        Next i
    End With
    
End Sub
 
Upvote 0
2. Instead of the code starting to paste in column H as the dates will change frequently, can it look up the date in the upload tab row 48 and match it to the date in the final tab row 1 before pasting?
Can you please explain in more detail what you mean by this? (Bearing in mind that we have no idea where your dates are, and which dates you want to match).
 
Last edited:
Upvote 0
I have 2 sheets, call it ‘upload’ and ‘final’.
There are calculations that are run behind the scenes I.e. other tabs that require Columns E:AN from the upload tab to be copied and pasted one at a time to the Final tab.
Need a macro, that essentially does this.
  1. Copies E56,E61,E66 from Upload tab and pastes in final tab by looking up the dates in row 1 and matching to the date in row 48 in the upload tab.
For example, E56,E61 and E66 will be pasted in F2,F3 and F4 in the final tab.

2. The macro will then continue doing this so, it will copy the next 3 in the upload tab E57,E62,E67 and paste in the appropriate cells in the final tab until we get to the last column say AN.

The cells in the upload tab need to be filled up one at a time (3 participants at a time) for the calculations to work, hence why an INDEX MATCH won’t work as the numbers change once pasted.
Also needs to be dynamic, hence why it looks up date before pasting as the dates will change.
Thank you.


test macro.xlsx
BCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARASATAUAV
43
44
45
46Participants
47
48Row Labels11/30/202412/31/202401/31/202502/28/202503/31/202504/30/202505/31/202506/30/202507/31/202508/31/202509/30/202510/31/202511/30/202512/31/202501/31/202602/28/202603/31/202604/30/202605/31/202606/30/202607/31/202608/31/202609/30/202610/31/202611/30/202612/31/202601/31/202702/28/202703/31/202704/30/202705/31/202706/30/202707/31/202708/31/202709/30/202710/31/202711/30/202712/31/202701/31/202802/29/202803/31/202804/30/202805/31/202806/30/2028
49A9,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,8599,859
50B5,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,4445,444
51C6,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,5556,555
52585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585585,858,585##################################585,858,585
53
54A
55A
56A395,949,4954,696,9696,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,46446,4644543354536,56546,46446,46446,46446,46446,4645,555433-
57
58
59B
60B
61B4,546,5676,76646,464817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,683817,6833,422817,6833,4333,423817,683817,683817,6833,443343817,68334,343,434343--
62
63
64C
65C
66C7,676656,5658,877787878787878787878787878787878783,434,3434,343,4337878787878787878783,43334,343783,43478787878787834343,433-
67
68
69
70
Upload


test macro.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAO
1ParticipantsJul-24Aug-24Sep-24Oct-24Nov-24Dec-24Jan-25Feb-25Mar-25Apr-25May-25Jun-25Jul-25Aug-25Sep-25Oct-25Nov-25Dec-25Jan-26Feb-26Mar-26Apr-26May-26Jun-26Jul-26Aug-26Sep-26Oct-26Nov-26Dec-26Jan-27Feb-27Mar-27Apr-27May-27Jun-27Jul-27Aug-27Sep-27Oct-27
2A8,787,878.0054,565,465.0067,676.006,676.00
3B6,767,678.0056,655.007,645,435.00754.00
4C34,434,343.00767,667.0054,544.009,548.00
5
6D6,767.004,545.00565,656,564.0076,764.00
7E4,545.006,767.007,676.004,354,544.00
8F----
9
10G8,599.00545,454.00454.004,545.00
11H545.00-94,394.00454.00
12II454.0076.00545,466,565.00-
13
14J4,532.004,545.004,545.00567,786.00
15K----
16L2,324,324.0054,545.0065,656,565.0067,657.00
17
18M----
19N7,676.005,656.00665,656.0056,565.00
20O---56,565.00
21---
22P----
23Q765,434.004,565,656.0056,567.006,565.00
24R----
25----
26S5,555.0022,466,777.00343,456.0075,665,565.00
27T55,567,676.004,554.0067,645,453.0056,565,643.00
28U----
29----
30V5,454.005,653.00-54,453.00
31W554,567.00898,989.0078,708.00434,345.00
32X424.003.0076,545.0056,677,667.00
33----
34Y43,243,435.00545.005,454.0022,323.00
35Z----
36AB15,454.00343.00-232.00
37----
38QC2-354,545.00543,342.00-
39DF4
40DG65.00545,454.0054.00544.00
Final
 
Upvote 0
I don't know if you saw Post #2? That code does everything that the code in Post #1 does.

Your Upload screenshot shows results for:

A in row 56
B in row 61
C in row 66

Does this pattern continue, e.g.

D in row 71
E in row 76
F in row 81?

If so, we can wrap the code in Post #2 in a loop that iterates through the ten groups.

Alternatively, we could use a formula (or have VBA use that formula, and replace with values). Assuming the above pattern continues, and assuming you want all the columns copied across, this formula in Final!F2 should populate the required results:

Excel Formula:
=LET(Upload,IF(Upload!E56:AV318="","",Upload!E56:AV318),inc,5,grp,ROWS(A2:A5),s,SEQUENCE(ROWS(A2:A41),,0),r,1+inc*s-inc*INT(s/grp),x,IF(MOD(s,grp)=grp-1,"",CHOOSEROWS(Upload,r)),x)

However ...
There are calculations that are run behind the scenes I.e. other tabs that require Columns E:AN from the upload tab to be copied and pasted one at a time to the Final tab.

The cells in the upload tab need to be filled up one at a time (3 participants at a time) for the calculations to work, hence why an INDEX MATCH won’t work as the numbers change once pasted.

Sorry, I don't follow this at all. What does "behind the scenes" mean? Were you correct in saying "the cells in the upload tab need to be filled up one at a time"?

I am only guessing that:

- You do want all columns, not just the November 2024 column, to be pasted into Final
- The December 2024 and subsequent columns will be overwritten when the next Upload is available?
 
Upvote 0
I don't know if you saw Post #2? That code does everything that the code in Post #1 does.

Your Upload screenshot shows results for:

A in row 56
B in row 61
C in row 66

Does this pattern continue, e.g.

D in row 71
E in row 76
F in row 81?

If so, we can wrap the code in Post #2 in a loop that iterates through the ten groups.

Alternatively, we could use a formula (or have VBA use that formula, and replace with values). Assuming the above pattern continues, and assuming you want all the columns copied across, this formula in Final!F2 should populate the required results:

Excel Formula:
=LET(Upload,IF(Upload!E56:AV318="","",Upload!E56:AV318),inc,5,grp,ROWS(A2:A5),s,SEQUENCE(ROWS(A2:A41),,0),r,1+inc*s-inc*INT(s/grp),x,IF(MOD(s,grp)=grp-1,"",CHOOSEROWS(Upload,r)),x)

However ...


Sorry, I don't follow this at all. What does "behind the scenes" mean? Were you correct in saying "the cells in the upload tab need to be filled up one at a time"?

I am only guessing that:

- You do want all columns, not just the November 2024 column, to be pasted into Final
- The December 2024 and subsequent columns will be overwritten when the next Upload is available?
thank you. sorry, I should have been clearer. behind the scenes- in the upload sheet, the cells to be copied are formula driven, so once the first column is pasted in the final sheet, the values for the next column changes in the upload sheet. its an amortization schedule, so the values change once the values are copied and pasted.
hence, they need to be copied and pasted one after the other.
ignore everything apart from below, the idea is that once I have the code, I can replicate it in the other iterations for the other groups by just changing the column and row numbers.

I need the macro to

1. copy the values from the upload sheet in E56,E61,E66
2. FIND THE STARTING POINT to paste the data- lookup the date in upload sheet E48 and match the date in the final sheet row 1. (right now, it will be F1 i.e November 2024, but in another period, November 2024 might be in E1 or D1.
3. once the appropriate column is matched in this case F1, paste the values in rows F2,F3,F4.
4. then since we have the starting point for the paste as F2,F3,F4- copy the next set of values from the upload sheet which will be F56,F61,F66 then paste in the next column in the final sheet so, G2,G3,G4.
5. then copy from upload sheet G56,G61,G66 and paste in the final sheet H2,H3,H4.
6. keep doing this one column to the right at a time until column AN in the upload sheet is copied and pasted.

its just a copy and paste code one at a time, but it needs to find the starting point for where it should paste by looking up the date.
 
Upvote 0
I don't know if you saw Post #2? That code does everything that the code in Post #1 does.

Your Upload screenshot shows results for:

A in row 56
B in row 61
C in row 66

Does this pattern continue, e.g.

D in row 71
E in row 76
F in row 81?

If so, we can wrap the code in Post #2 in a loop that iterates through the ten groups.

Alternatively, we could use a formula (or have VBA use that formula, and replace with values). Assuming the above pattern continues, and assuming you want all the columns copied across, this formula in Final!F2 should populate the required results:

Excel Formula:
=LET(Upload,IF(Upload!E56:AV318="","",Upload!E56:AV318),inc,5,grp,ROWS(A2:A5),s,SEQUENCE(ROWS(A2:A41),,0),r,1+inc*s-inc*INT(s/grp),x,IF(MOD(s,grp)=grp-1,"",CHOOSEROWS(Upload,r)),x)

However ...


Sorry, I don't follow this at all. What does "behind the scenes" mean? Were you correct in saying "the cells in the upload tab need to be filled up one at a time"?

I am only guessing that:

- You do want all columns, not just the November 2024 column, to be pasted into Final
- The December 2024 and subsequent columns will be overwritten when the next Upload is available?
Not sure if you saw the reply. Please are you able to help. Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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