Add days to date in excel cell

Hello I try to compute days from an excel cell formatted as a date but fail to get results.

Here is my piece of script


tell application "Microsoft Excel"
	
	set sourceBook to active workbook
	set destinationBook to first workbook
	
	--> Closing Date
	set sourceRange to get range "AY12" of active sheet of sourceBook
	set destinationRange to get range "E10" of active sheet of destinationBook
	set value of destinationRange to (date string of (get value of sourceRange)) + (days * 2)
	
end tell

Can anyone point out my mistake?

Thanks

There’s more than one:

  • your’e setting a cell to a date, so you want a date object, not a date string
  • days is an AppleScript constant, and Excel has no idea what to do with it
  • a matter of preference: don’t use range when dealing with single cells

With those changes it could look like this:

set intDays to days

tell application "Microsoft Excel"
	
	set sourceBook to active workbook
	
	set sourceCell to cell "A1" of active sheet of sourceBook
	set destinationCell to cell "A10" of active sheet of sourceBook
	set value of destinationCell to (get value of sourceCell) + intDays * 2
		
end tell

Thank you alastor933.

Works fine now…Thanks for your help.

By the way I am passing information from one workbook to another that is why I had sourcebook and destination book.:wink: