简体   繁体   English

是否有任何 function 可以为特定单元格添加日期?

[英]Is there any function to add date to specific cells?

I neeed some help about my company staff attendance record form.我需要一些有关我公司员工出勤记录表的帮助。 The form is like this Many cells are missing date, for example, some cells of BE column miss 1.24, I want to create a function that can pop up a box and I can enter the date[1.24], but I do not want to add 1.24 to each cell;表格是这样的很多单元格都缺少日期,例如BE列的某些单元格缺少1.24,我想创建一个function,可以弹出一个框,我可以输入日期[1.24],但我不想每个单元格加 1.24; I want to add 1.24 to these cells that miss the date.我想将 1.24 添加到这些错过日期的单元格中。 Does this can be achieved?这可以实现吗? Thank u so much for helping me!非常感谢你帮助我!

Yes, you can achieve this using a macro in Microsoft Excel. Macros are a set of instructions that automate tasks in Excel. You can create a macro to add the date you enter to specific cells in a column.是的,您可以使用 Microsoft Excel 中的宏来实现此目的。宏是一组指令,可自动执行 Excel 中的任务。您可以创建宏以将输入的日期添加到列中的特定单元格。 Here's how you can create a macro in Excel:以下是在 Excel 中创建宏的方法:

Open the Microsoft Excel workbook containing the form you want to add a date to.打开包含要添加日期的表单的 Microsoft Excel 工作簿。 Press Alt + F11 to open the VBA Editor.按 Alt + F11 打开 VBA 编辑器。 In the VBA Editor, select the workbook that contains the form from the Project Explorer window on the left.在 VBA 编辑器中,select 工作簿包含来自左侧 Project Explorer window 的表单。 From the Insert menu, select Module.从插入菜单中,select 模块。 A new module will appear in the Code window. Copy and paste the following code into the module: Sub AddDateToCell() Dim rng As Range Dim dateInput As Variant Set rng = Application.InputBox("Select the cells where you want to add the date", Type:=8) dateInput = Application.InputBox("Enter the date you want to add to the cells", Type:=2) rng.Value = dateInput End Sub Save the macro by clicking the Save button on the toolbar or by selecting Save from the File menu.代码 window 中将出现一个新模块。将以下代码复制并粘贴到模块中:Sub AddDateToCell() Dim rng As Range Dim dateInput As Variant Set rng = Application.InputBox("选择要添加日期的单元格", Type:=8) dateInput = Application.InputBox("Enter date you want to add to the cells", Type:=2) rng.Value = dateInput End Sub 通过单击工具栏上的保存按钮保存宏或通过从文件菜单中选择保存。 Close the VBA Editor by clicking the X in the top right corner.单击右上角的 X 关闭 VBA 编辑器。 Return to the Excel workbook and select the cells that are missing the date.返回 Excel 工作簿和 select 缺少日期的单元格。 From the Developer tab, select Macros.在“开发人员”选项卡中,select 宏。 Select the AddDateToCell macro from the list and click the Run button. Select 从列表中添加 AddDateToCell 宏并单击运行按钮。 In the Input Box, enter the date you want to add to the cells.在输入框中,输入要添加到单元格的日期。 The date will be added to the cells you selected.日期将添加到您选择的单元格中。 Note: The above code assumes that the cells you want to add the date to are empty.注意:以上代码假定您要添加日期的单元格为空。 If they contain data, the data will be overwritten by the date you enter.如果它们包含数据,则数据将在您输入的日期之前被覆盖。

Yes, you can add a date to specific cells in Google Sheets using a script.是的,您可以使用脚本向 Google 表格中的特定单元格添加日期。 To do this, you'll need to use the prompt function to create a dialog box that will ask you to input the date, and the getActiveRange function to identify the cells that you want to add the date to.为此,您需要使用提示符 function 创建一个要求您输入日期的对话框,并使用 getActiveRange function 来识别要添加日期的单元格。 Here's an example of what the code might look like:下面是代码的示例:

function addDate() { function 添加日期(){

var sheet = SpreadsheetApp.getActiveSheet(); var sheet = SpreadsheetApp.getActiveSheet();

var range = sheet.getActiveRange(); var range = sheet.getActiveRange();

var date = new Date(prompt("Enter the date in format YYYY-MM-DD:", "")); var date = new Date(prompt("请以 YYYY-MM-DD 格式输入日期:", ""));

range.setValue(date);范围.setValue(日期); } }

You can then add this function to your Google Sheet by going to Tools > Script editor in the menu.然后,您可以通过转到菜单中的工具 > 脚本编辑器,将此 function 添加到您的 Google 表格中。 In the script editor, you can run the function by clicking the play button or by going to Run > addDate.在脚本编辑器中,您可以通过单击播放按钮或转到运行 > addDate 来运行 function。

This will add the date to the active cells in the sheet.这会将日期添加到工作表中的活动单元格。 If you want to only add the date to specific cells, you'll need to modify the range variable to only include those cells.如果您只想将日期添加到特定单元格,则需要修改范围变量以仅包含这些单元格。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 onEdit 可安装触发器,当在任何单元格范围内选择特定值(全部带有下拉菜单)时,如何调用 function? - Using onEdit installable trigger, how do I call a function when a specific value is selected in any of a range of cells(all with dropdowns)? 为具有日期时间值的单元格过滤 function - Filter function for cells with Date Time values 颜色填充与列中的任何日期匹配的所有单元格 - Colour fill all cells that match any date in a column 是否存在Google Apps脚本来在特定日期解除对一系列单元格的保护? - Does a Google Apps Script exist to unprotect a range of cells at a specific date? 为任何特定时区创建新日期 - Create a new Date for any specific timezone 有一个函数仅使用> = Google文档中日期的范围内的单元格 - Have a function only use cells in it's range that are >= a date in google docs 更改查询中特定列中所有单元格的文本 () function - Change the text of all cells in a specific column in a Query () function 如何使用谷歌表格转置一组与特定输入日期相对应的单元格? - How to use google sheets to transpose a set of cells that correspond to a specific input date? 如何在监视特定单元格和注释的更改时自动创建日期戳 - How to automatically create a Date Stamp while monitoring specific Cells and Notes for changes 根据同一行的另一个单元格中的日期,自动在 Google 电子表格的单元格中插入特定文本的脚本 - Script to automatically insert a specific text in cells of a Google spreadsheet, based on a date in another cell, on the same row
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM