Add a new row when marked as yes but the date is updated

DMO123

Board Regular
Joined
Aug 16, 2018
Messages
99
Hi,

i am hoping someone can help. i have been trying to do the below but i am not getting close to what i want:

in columns B:J (starting on row 4) i have data. when "Yes" is marked in column H i need the sheet to copy the line add it to the bottom of the table with the date updated by however many months is written in column F for example:

Column B has dates so the date is 21-Mar-19 in column F i have 3 (meaning 3 months repetition) so when i mark column H as "Yes" the VBA will copy this row from B:J, add it to the bottom of the table updating the date in column B to 21-Jun-19 (from column F and the 3 month repetition).

can someone help?

thank you in advance.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
If no, then try:

Code:
Sub copybelow()


Dim rownum As Long
Dim Lastrow As Long
Dim counter As Long
Dim mynewdate As Date
Dim myolddate As Date
Dim sht As Worksheet


Set sht = ActiveSheet
Lastrow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row
rownum = 4
counter = 1


Do Until rownum = Lastrow + 1
If Cells(rownum, 8) = "Yes" Then
Range(Cells(rownum, 2), Cells(rownum, 10)).Copy Cells(Lastrow + counter, 2)
myolddate = Cells(Lastrow + counter, 2).Value
monthadd = Cells(Lastrow + counter, 6).Value
mynewdate = DateAdd("m", monthadd, myolddate)
Cells(Lastrow + counter, 2) = mynewdate
counter = counter + 1
End If
rownum = rownum + 1
Loop


End Sub
 
Last edited:
Upvote 0
Also i tried the code toy gave and it works but i would need it to paste as a value (if possible) as the data is pulled from another table.
 
Upvote 0
So looking into this further i have made this work with a button - would it be possible to make it run in the background? if so how do i do this?
 
Upvote 0
Hi,

So how often does it need to reoccur? It could go on forever if there's no limit.

Updated below for values

Code:
Sub copybelow()




Dim rownum As Long
Dim Lastrow As Long
Dim counter As Long
Dim mynewdate As Date
Dim myolddate As Date
Dim sht As Worksheet




Set sht = ActiveSheet
Lastrow = sht.Cells(sht.Rows.Count, "B").End(xlUp).Row
rownum = 4
counter = 1




Do Until rownum = Lastrow + 1
If Cells(rownum, 8) = "Yes" Then
Range(Cells(rownum, 2), Cells(rownum, 10)).Copy
Cells(Lastrow + counter, 2).PasteSpecial xlPasteValues
myolddate = Cells(Lastrow + counter, 2).Value
monthadd = Cells(Lastrow + counter, 6).Value
mynewdate = DateAdd("m", monthadd, myolddate)
Cells(Lastrow + counter, 2) = mynewdate
counter = counter + 1
End If
rownum = rownum + 1
Loop

What do you mean by in the background? What would you like it to do?
 
Upvote 0
thank you for this - by running in the background i mean when a value is entered in that column the VBA is triggered. so when i enter yes then click of the cell the VBA runs, it could be when i move sheets if easier?
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,263
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top