Divakarkumar
New Member
- Joined
- Jul 31, 2020
- Messages
- 9
- Office Version
- 2016
- Platform
- Windows
Hi All,
I’m automating one task, I have calculation sheet which contains the pivot table (A5:C18) and each row I need to paste in Sheet2 worksheet 3 times the same value and when it comes to next iteration in the loop it has given 2 blank rows and paste in sheet 2.
I have developed pies of code, but if condition is not satisfying, not sure my code is correct or wrong.
Great if some one helps on this
Code :
===================================
Sub CopyPastMultipleTimes()
Dim q As Long, p As Long
Dim wsl As Worksheet
Dim co As Variant
Set wsl = Worksheets("Calculation")
Lasrow = wsl.Range("A" & Rows.Count).End(xlUp).Row
wsl.Activate
For p = 5 To lastrow
If wsl.Cells(p, 1) = co Then
For q = 1 To 3
wsl.Range(Cells(p, 1), Cells(p, 2)).Copy Destination:=Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(2)
Next q
End If
Next p
End Sub
Sample data set;
Sheet Name : Calculation (Input sheet)
Out Put sheet :
Data should be like this
I’m automating one task, I have calculation sheet which contains the pivot table (A5:C18) and each row I need to paste in Sheet2 worksheet 3 times the same value and when it comes to next iteration in the loop it has given 2 blank rows and paste in sheet 2.
I have developed pies of code, but if condition is not satisfying, not sure my code is correct or wrong.
Great if some one helps on this
Code :
===================================
Sub CopyPastMultipleTimes()
Dim q As Long, p As Long
Dim wsl As Worksheet
Dim co As Variant
Set wsl = Worksheets("Calculation")
Lasrow = wsl.Range("A" & Rows.Count).End(xlUp).Row
wsl.Activate
For p = 5 To lastrow
If wsl.Cells(p, 1) = co Then
For q = 1 To 3
wsl.Range(Cells(p, 1), Cells(p, 2)).Copy Destination:=Worksheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(2)
Next q
End If
Next p
End Sub
Sample data set;
Sheet Name : Calculation (Input sheet)
CO | IC | Ent. Curr | Sum of Entered DEBIT/CREDIT | Sum of Accounted DEBIT/CREDIT |
630 | 310 | EUR | 132,495 | 148,437 |
630 | 631 | HKD | 658,042 | 84,858 |
630 | 631 | THB | 1,444,500 | 45,258 |
630 | 631 | AUD | 250,631 | 161,281 |
630 | 631 | INR | 23,239,770 | 306,765 |
631 | 310 | EUR | (327,877) | (367,329) |
631 | 630 | HKD | (658,042) | (84,858) |
631 | 630 | THB | (1,444,500) | (45,258) |
631 | 630 | AUD | (250,631) | (161,281) |
631 | 630 | INR | (23,239,770) | (306,765) |
631 | 300 | EUR | (2,357,890) | (2,641,597) |
631 | 300 | GBP | 1,269 | 1,563 |
631 | 300 | CHF | (198,564) | (209,147) |
631 | 300 | ZAR | 5,388 | 311 |
Grand Total | (2,745,179) | (3,067,762) |
Out Put sheet :
Data should be like this
CO | IC | Ent. Curr | Sum of Entered DEBIT/CREDIT | Sum of Accounted DEBIT/CREDIT |
630 | 310 | EUR | 132,495 | 148,437 |
630 | 310 | EUR | 132,495 | 148,437 |
630 | 310 | EUR | 132,495 | 148,437 |
630 | 631 | HKD | 658,042 | 84,858 |
630 | 631 | HKD | 658,042 | 84,858 |
630 | 631 | HKD | 658,042 | 84,858 |