Home > Enterprise >  How to copy and paste using looping?
How to copy and paste using looping?

Time:01-23

How to copy and paste using looping? I want to copy the data in month like from jan, feb, in january i want to copy the data from 1-31 since january has 31 days and if in february or other month that no 31 i want to copy only the exact data for that month like from feb only has 28 days.

Im new in VBA and i dont know how to loop, can someone help me? thank you.

CodePudding user response:

Set original = Worksheets(1) Set destination = ThisWorkbook.Sheets(2)

original.Range("D6:D155").Copy
destination.Range("F4:F150").PasteSpecial xlPasteValues

original.Range("H6:H155").Copy
destination.Range("G4:G150").PasteSpecial xlPasteValues

original.Range("L6:L155").Copy
destination.Range("H4:H150").PasteSpecial xlPasteValues

original.Range("P6:P155").Copy
destination.Range("I4:I150").PasteSpecial xlPasteValues

original.Range("T6:T155").Copy
destination.Range("J4:J150").PasteSpecial xlPasteValues

original.Range("X6:X155").Copy
destination.Range("K4:K150").PasteSpecial xlPasteValues

original.Range("AB6:AB155").Copy
destination.Range("L4:L150").PasteSpecial xlPasteValues

original.Range("AF6:AF155").Copy
destination.Range("M4:M150").PasteSpecial xlPasteValues

original.Range("AJ6:AJ155").Copy
destination.Range("N4:N150").PasteSpecial xlPasteValues

original.Range("AN6:AN155").Copy
destination.Range("O4:O150").PasteSpecial xlPasteValues

original.Range("AR6:AR155").Copy
destination.Range("P4:P150").PasteSpecial xlPasteValues

original.Range("AV6:AV155").Copy
destination.Range("Q4:Q150").PasteSpecial xlPasteValues

original.Range("AZ6:AZ155").Copy
destination.Range("R4:R150").PasteSpecial xlPasteValues

original.Range("BD6:BD155").Copy
destination.Range("S4:S150").PasteSpecial xlPasteValues

original.Range("BH6:BH155").Copy
destination.Range("T4:T150").PasteSpecial xlPasteValues

original.Range("BL6:BL155").Copy
destination.Range("U4:U150").PasteSpecial xlPasteValues

original.Range("BP6:BP155").Copy
destination.Range("V4:V150").PasteSpecial xlPasteValues

original.Range("BT6:BT155").Copy
destination.Range("W4:W150").PasteSpecial xlPasteValues

original.Range("BX6:BX155").Copy
destination.Range("X4:X150").PasteSpecial xlPasteValues

original.Range("CB6:CB155").Copy
destination.Range("Y4:Y150").PasteSpecial xlPasteValues

original.Range("CF6:CF155").Copy
destination.Range("Z4:Z150").PasteSpecial xlPasteValues

original.Range("CJ6:CJ155").Copy
destination.Range("AA4:AA150").PasteSpecial xlPasteValues

original.Range("CN6:CN155").Copy
destination.Range("AB4:AB150").PasteSpecial xlPasteValues

original.Range("CR6:CR155").Copy
destination.Range("AC4:AC150").PasteSpecial xlPasteValues

original.Range("CV6:CV155").Copy
destination.Range("AD4:AD150").PasteSpecial xlPasteValues

original.Range("CZ6:CZ155").Copy
destination.Range("AE4:AE150").PasteSpecial xlPasteValues

original.Range("DD6:DD155").Copy
destination.Range("AF4:AF150").PasteSpecial xlPasteValues

original.Range("DH6:DH155").Copy
destination.Range("AG4:AG150").PasteSpecial xlPasteValues

original.Range("DL6:DL155").Copy
destination.Range("AH4:AH150").PasteSpecial xlPasteValues
  
original.Range("DP6:DP155").Copy
destination.Range("AI4:AI150").PasteSpecial xlPasteValues

original.Range("DT6:DT155").Copy
destination.Range("AJ4:AJ150").PasteSpecial xlPasteValues

here is my code

CodePudding user response:

enter image description here

here is the input file, i want to copy only the numbers from range D6:D155 - H6:D155... up to the last day of the month DP6:DP155

  • Related