VBA to increase the date based on other cells

DanielJeff

New Member
Joined
Apr 26, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I'm after a bit of help with writing a VBA.
I'm putting together a sheet to help finance when to chase based on our 28day invoices.
I have all the invoice dates in column B and am looking to write a VBA to create a new date in column E. This new date will be the invoice date + 28 days.
Is there any way to do this.
F0024808/02/2023R2844441.44
F0031520/03/2023R28668577.26
F0055416/02/2023R285204035.05
F0061404/04/2023R286982129.45
F0064716/01/2023R279151297.30
F0106015/02/2023R28517626.14
F0112305/01/2023R276544540.09
F0115718/01/2023R2804376.97
F0128720/02/2023R28550534.67
F0170010/02/2023R28467448.98
F0180901/02/2023R28371477.19
F0211515/03/2023R28654549.04
F0220522/03/2023R28674566.10
F0267614/02/2023R284943989.50
F0301201/02/2023R28368279.36
F0336309/02/2023R284584181.93
F0355320/01/2023R28137555.46
F0370304/10/2022R25426478.80
F0396711/04/2023R28700496.32
Thanks
Daniel
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Welcome to the Board!

Why does it need to be VBA? It can be done with a rather simple formula, i.e. for cell E2 the formula would just be:
Excel Formula:
=B2+28

If you truly need it in VBA, it is really the same logic, i.e.
VBA Code:
Range("E2").Value = Range("B2").Value + 28
 
Upvote 0
If you are looking to update all rows at once, you can use this VBA code:
VBA Code:
Sub Insert_Dates()

    Dim lr As Long
    
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
    
'   Populate all rows from row 2 to end with formula in column E
    Range("E2:E" & lr).FormulaR1C1 = "=RC[-3]+28"
    
End Sub
 
Upvote 0
If you are looking to update all rows at once, you can use this VBA code:
VBA Code:
Sub Insert_Dates()

    Dim lr As Long
   
'   Find last row in column B with data
    lr = Cells(Rows.Count, "B").End(xlUp).Row
   
'   Populate all rows from row 2 to end with formula in column E
    Range("E2:E" & lr).FormulaR1C1 = "=RC[-3]+28"
   
End Sub
Joe that's a life saver, thanks for that. Works perfectly

Formulas would be a lot simpler but Its all part of a larger VBA i was trying to put together.
The original document needed to have merged cells removed, redundant columns and rows removed and a few cells dropping down. All of that i've been able to do, but was really struggling with how to take the date and add 28 days to it.
 
Upvote 0
Makes sense.
You are welcome.
Glad I was able to help!
:)
 
Upvote 0

Forum statistics

Threads
1,215,582
Messages
6,125,659
Members
449,247
Latest member
wingedshoes

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