• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need to edit the VBA

pao13

Member
Hi. I would like to revise a little the following macro. When i=y (the last row in sheet "events exp up to 2 months") I would like the result to come once not twice. So duplicate rows until the last which I would like it to come up once.

Thanks for any answers!

Code:
Sub copy_paste_events_P_L_events_2_months()
Dim i As Long, y As Long
y = Sheets("events exp up to 2 months").Range("T" & Rows.Count).End(3).Row
For i = 9 To y
Sheets("P_L events up to 2 months").Range("B" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("R" & i).Value
Sheets("P_L events up to 2 months").Range("B" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("R" & i).Value
Sheets("P_L events up to 2 months").Range("C" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("S" & i).Value
Sheets("P_L events up to 2 months").Range("C" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("S" & i).Value
Sheets("P_L events up to 2 months").Range("D" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("T" & i).Value
Sheets("P_L events up to 2 months").Range("D" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("T" & i).Value
Next i
End Sub
 
Hi Pao,

Try this way :

Code:
Sub copy_paste_events_P_L_events_2_months()
Dim i As Long, y As Long

y = Sheets("events exp up to 2 months").Range("T" & Rows.Count).End(3).Row

For i = 9 To y
Sheets("P_L events up to 2 months").Range("B" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("R" & i).Value
Sheets("P_L events up to 2 months").Range("C" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("S" & i).Value
Sheets("P_L events up to 2 months").Range("D" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("T" & i).Value
If i = y Then Exit Sub
Sheets("P_L events up to 2 months").Range("B" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("R" & i).Value
Sheets("P_L events up to 2 months").Range("C" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("S" & i).Value
Sheets("P_L events up to 2 months").Range("D" & Rows.Count).End(3)(2).Value = Sheets("events exp up to 2 months").Range("T" & i).Value
Next i
End Sub
 
Thanks for your help but the results are the same with before (duplicate row at the end). I attached the file if you could take a look. I have named the module copy_paste_1
 

Attachments

  • RSX DATA question f.xlsm
    198.9 KB · Views: 0
Back
Top