PDA

View Full Version : Create a Code to update Date



asheesh3337
10-04-2015, 07:21 PM
I have an Excel workbook with dates.

1. If Updation cells as "Y" and If Status as "H" then Date+6 months in next

2. If Updation cells as "Y" and If Status as "Q" then Date+3 months

Help is needed to create a code for updating the "Next Date" {if Status cells has "Y"} as per the above conditions.


Attached is the file for your refrence, would like to thanks in advance for the help.

alansidman
10-04-2015, 08:18 PM
Try this:


Option Explicit


Sub ams()
Dim i As Long, lr As Long
lr = Range("A" & Rows.Count).End(xlUp).Row

Application.ScreenUpdating = False
For i = 2 To lr
If Range("E" & i) = "Y" Then
If Range("D" & i) = "H" Then
Range("F" & i) = DateAdd("m", 6, Range("F" & i))
ElseIf Range("D" & i) = "Q" Then
Range("F" & i) = DateAdd("m", 3, Range("F" & i))
End If
End If
Next i
Application.ScreenUpdating = True
MsgBox "complete"




End Sub

asheesh3337
10-04-2015, 11:15 PM
Thanks, it is working. I am developing a sheet will get intouch in case I will feel stuck at any point. I hope you will not mind this.