kuldeepnagar
New Member
- Joined
- May 9, 2019
- Messages
- 12
Dear All
I have one sheet named "Active" and data starts in this sheet from B4. I have one more sheet named "Lapsed" and data starts in this sheet from B3.
When date in H column in "Active" sheet in less than now -120 days, code will copy contents of B to G column of respective row and paste in next empty row of "Lapsed" Sheet.
I am facing following issues.
1. If I run code 2 time, it deletes one row from "Lapsed" sheet.
2. If i run code when date condition is met, code will delete last filled row in "Lapsed" sheet, leave one row blank and paste data to next date.
I do not want above to issues. Please support. I started learning VBA and made below code with help of numerous webs from Excel Experts. Your expert opinion will surely be appreciable. Thanks a lot in advance.
I have one sheet named "Active" and data starts in this sheet from B4. I have one more sheet named "Lapsed" and data starts in this sheet from B3.
When date in H column in "Active" sheet in less than now -120 days, code will copy contents of B to G column of respective row and paste in next empty row of "Lapsed" Sheet.
I am facing following issues.
1. If I run code 2 time, it deletes one row from "Lapsed" sheet.
2. If i run code when date condition is met, code will delete last filled row in "Lapsed" sheet, leave one row blank and paste data to next date.
I do not want above to issues. Please support. I started learning VBA and made below code with help of numerous webs from Excel Experts. Your expert opinion will surely be appreciable. Thanks a lot in advance.
Code:
Sub RectangleRoundedCorners4_Click()
Application.ScreenUpdating = False
Dim wsI As Worksheet, wsO As Worksheet
Dim LastRow As Long, i As Long, j As Long
Dim LastColumn As Long, a As Long, b As Long
Dim rng As Range
Set wsI = Sheets("Active")
Set wsO = Sheets("Lapsed")
Set rng = wsI.Range("B:G")
'Last Row in a Column. Row need to start in row 2
LastRow = wsI.Cells(Rows.Count, "G").End(xlUp).Row
j = wsO.Cells(Rows.Count, "B").End(xlUp).Row
With wsI
'Loop through each row
For i = 2 To LastRow
If .Range("H" & i).Value <= Date - 120 Then
wsI.Range("B" & i & ":G" & i).Copy
wsO.Cells(j, "B").PasteSpecial Paste:=xlPasteValues
wsI.Range("B" & i & ":G" & i).ClearContents
j = j + 1
End If
Next i
End With
Last edited by a moderator: