Numbers auto date fill

I created a spreadsheet to track transactions for customer accounts, I will be using it periodically rather than every single day. I would like to have the date generated automatically per usage rather than automatically fill in every day ahead of time... Is there a way to do this?


So my date column & row start at B7. The only way I can seem to get the date to generate at all is by clicking B8 and entering formula "=B7+1" and then dragging all the way down but it pre fills consecutively for every date after the first entered. I don't want it pre filled or consecutive. Just as per date that data is entered.


Does this make sense to anyone? Can anyone make it make sense? Please help!

Posted on Jan 22, 2022 10:24 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 22, 2022 2:44 PM

Not built into Numbers. There is an AppleScript to do it. You can use Automator to turn it into Service/Quick Action and assign a keyboard shortcut to it. You can try it out as a script first. It does have one flaw: when you click a date in the picker it does not highlight it to show what date you picked. The date picker itself is not something we can access to change that behavior. The script just applies it to Numbers.


  1. Open the Script Editor app.
  2. Copy/paste the entire script below into a new window in that app.
  3. Go back to Numbers and select a cell or range of cells
  4. Go back to Script Editor and hit the Play button to run the script


If you like it and want to assign a keyboard shortcut to it,

  1. Open the Automator app
  2. Create a new Quick Action
  3. Set it so workflow receives no input for application Numbers
  4. Drag in the Run AppleScript action from the Utilities folder.
  5. Delete everything in the action
  6. Paste the script from below into the action
  7. Save it (with a short menu-like name preferably) and it will appear in the Numbers/Services menu
  8. Go to System Preferences/Keyboard/Shortcuts/App Shortcuts
  9. Click the + to create a new shortcut
  10. Type in the exact name, case sensitive. It is for Application Numbers.
  11. Choose a shortcut. Command Option Shift D for example.
  12. Click Add


I hope that was all correct. I ought to save these instructions so I can copy/paste them here vs typing it all in from memory every time.


-- Author: Shane Stanley
-- Edited by Badunit for use within the Numbers app
-- This version is edited to work around Apple's newly introduced selection range bug
-- Nov 22, 2021

use scripting additions
use framework "AppKit"

property thedate : missing value
property returncode : missing value

on run
	its performSelectorOnMainThread:("showDatePicker:") withObject:{} waitUntilDone:true
	
	tell application "Numbers" to tell the front document to tell active sheet to tell (first table whose class of selection range is range)
		set therange to every cell of range (get name of selection range)
		repeat with c in therange
			set value of c to thedate
		end repeat
	end tell
	
end run

on showDatePicker:params
	local params
	
	set datePicker to current application's NSDatePicker's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 100))
	
	-- set datepicker style: choices are 
	-- NSTextFieldAndStepperDatePickerStyle 
	-- NSClockAndCalendarDatePickerStyle
	-- NSTextFieldDatePickerStyle
	
	datePicker's setDatePickerStyle:(current application's NSClockAndCalendarDatePickerStyle)
	
	-- set datepicker elements: choices include 
	-- NSHourMinuteDatePickerElementFlag
	-- NSHourMinuteSecondDatePickerElementFlag
	-- NSTimeZoneDatePickerElementFlag
	-- NSYearMonthDatePickerElementFlag
	-- NSEraDatePickerElementFlag
	
	datePicker's setDatePickerElements:((current application's NSYearMonthDayDatePickerElementFlag) + (current application's NSHourMinuteSecondDatePickerElementFlag as integer))
	
	-- set datepicker initial date
	
	datePicker's setDateValue:(current application's NSDate's |date|())
	
	-- set datepicker size
	
	set theSize to datePicker's fittingSize()
	datePicker's setFrameSize:theSize
	
	-- set the view
	
	set theView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 200))
	theView's setFrameSize:theSize
	
	-- add the picker to the view
	
	theView's setSubviews:{datePicker}
	
	-- create an alert
	
	set theAlert to current application's NSAlert's alloc()'s init()
	
	-- set up alert
	
	tell theAlert
		its setMessageText:"Pick a Date"
		its setInformativeText:""
		its addButtonWithTitle:"Date & Time"
		its addButtonWithTitle:"Date Only"
		its addButtonWithTitle:"Cancel"
		its setAccessoryView:theView
	end tell
	
	-- show alert in modal loop
	
	set returncode to theAlert's runModal()
	
	
	-- retrieve date. First button is date & time. Second is date with time set to 12:00AM. Third is cancel
	
	if returncode = (current application's NSAlertFirstButtonReturn) then
		set thedate to datePicker's dateValue() as date
	else if returncode = (current application's NSAlertSecondButtonReturn) then
		set thedate to datePicker's dateValue() as date
		set time of thedate to 0
	else
		error number -128
	end if
	
end showDatePicker:

Similar questions

4 replies
Question marked as Top-ranking reply

Jan 22, 2022 2:44 PM in response to SelfTaughtStillLearning

Not built into Numbers. There is an AppleScript to do it. You can use Automator to turn it into Service/Quick Action and assign a keyboard shortcut to it. You can try it out as a script first. It does have one flaw: when you click a date in the picker it does not highlight it to show what date you picked. The date picker itself is not something we can access to change that behavior. The script just applies it to Numbers.


  1. Open the Script Editor app.
  2. Copy/paste the entire script below into a new window in that app.
  3. Go back to Numbers and select a cell or range of cells
  4. Go back to Script Editor and hit the Play button to run the script


If you like it and want to assign a keyboard shortcut to it,

  1. Open the Automator app
  2. Create a new Quick Action
  3. Set it so workflow receives no input for application Numbers
  4. Drag in the Run AppleScript action from the Utilities folder.
  5. Delete everything in the action
  6. Paste the script from below into the action
  7. Save it (with a short menu-like name preferably) and it will appear in the Numbers/Services menu
  8. Go to System Preferences/Keyboard/Shortcuts/App Shortcuts
  9. Click the + to create a new shortcut
  10. Type in the exact name, case sensitive. It is for Application Numbers.
  11. Choose a shortcut. Command Option Shift D for example.
  12. Click Add


I hope that was all correct. I ought to save these instructions so I can copy/paste them here vs typing it all in from memory every time.


-- Author: Shane Stanley
-- Edited by Badunit for use within the Numbers app
-- This version is edited to work around Apple's newly introduced selection range bug
-- Nov 22, 2021

use scripting additions
use framework "AppKit"

property thedate : missing value
property returncode : missing value

on run
	its performSelectorOnMainThread:("showDatePicker:") withObject:{} waitUntilDone:true
	
	tell application "Numbers" to tell the front document to tell active sheet to tell (first table whose class of selection range is range)
		set therange to every cell of range (get name of selection range)
		repeat with c in therange
			set value of c to thedate
		end repeat
	end tell
	
end run

on showDatePicker:params
	local params
	
	set datePicker to current application's NSDatePicker's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 100))
	
	-- set datepicker style: choices are 
	-- NSTextFieldAndStepperDatePickerStyle 
	-- NSClockAndCalendarDatePickerStyle
	-- NSTextFieldDatePickerStyle
	
	datePicker's setDatePickerStyle:(current application's NSClockAndCalendarDatePickerStyle)
	
	-- set datepicker elements: choices include 
	-- NSHourMinuteDatePickerElementFlag
	-- NSHourMinuteSecondDatePickerElementFlag
	-- NSTimeZoneDatePickerElementFlag
	-- NSYearMonthDatePickerElementFlag
	-- NSEraDatePickerElementFlag
	
	datePicker's setDatePickerElements:((current application's NSYearMonthDayDatePickerElementFlag) + (current application's NSHourMinuteSecondDatePickerElementFlag as integer))
	
	-- set datepicker initial date
	
	datePicker's setDateValue:(current application's NSDate's |date|())
	
	-- set datepicker size
	
	set theSize to datePicker's fittingSize()
	datePicker's setFrameSize:theSize
	
	-- set the view
	
	set theView to current application's NSView's alloc()'s initWithFrame:(current application's NSMakeRect(0, 0, 100, 200))
	theView's setFrameSize:theSize
	
	-- add the picker to the view
	
	theView's setSubviews:{datePicker}
	
	-- create an alert
	
	set theAlert to current application's NSAlert's alloc()'s init()
	
	-- set up alert
	
	tell theAlert
		its setMessageText:"Pick a Date"
		its setInformativeText:""
		its addButtonWithTitle:"Date & Time"
		its addButtonWithTitle:"Date Only"
		its addButtonWithTitle:"Cancel"
		its setAccessoryView:theView
	end tell
	
	-- show alert in modal loop
	
	set returncode to theAlert's runModal()
	
	
	-- retrieve date. First button is date & time. Second is date with time set to 12:00AM. Third is cancel
	
	if returncode = (current application's NSAlertFirstButtonReturn) then
		set thedate to datePicker's dateValue() as date
	else if returncode = (current application's NSAlertSecondButtonReturn) then
		set thedate to datePicker's dateValue() as date
		set time of thedate to 0
	else
		error number -128
	end if
	
end showDatePicker:

Jan 22, 2022 1:09 PM in response to SelfTaughtStillLearning

On the menu is Table/Insert Current Date. There is a keyboard shortcut associated with it that you can use.


You probably do not want to use a formula for the dates. The date is part of your data, not a formula. If one gets messed up, all your dates below it get hosed up. I would select all the cells with formulas, Copy, then Paste Formula Results to replace the formulas with the calculated values.

Jan 22, 2022 5:45 PM in response to SelfTaughtStillLearning

Going back to a "manual" method of placing the same date in several rows of a column.


Yesterday was January 21. I hsd 2 or more rows of data to enter on that date.


Today is January 22. expect to have several rows of data to enter today, but for the example, I say "at least six. I can add more later, or delete any extras.


Start by entering the new date in the next two cells of the column:



The two dates set in the selected cells determine the difference between dates (zero days) if the series is continued by filling the series down the page.


Select the two cells containing Jan 22, place the pointer near the bottom of the second cell to expose the Fill Control (small yellow circle at the middle of the cell's bottom boundary).

Place the pointer on the control. The pointer will change from and arrow head to a pair of up—down arrows. Press the mouse button and drag the control down the column to fill as many cells as needed.


You can add more copies of the same date at any time by selecting the last two, then filling down.


To start a new date (that is to be repeated), you need to place two copies of that date in consecutive cells to set the 'step' to zero, then proceed as above.


Regards,

Barry

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Numbers auto date fill

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.