[英]How can I get a cell within a range to hardcode once the cell changes?
I need to get a cell within a range to hardcode when a status is selected in another column (same row) on the worksheet.当在工作表上的另一列(同一行)中选择状态时,我需要获取范围内的单元格以进行硬编码。 The purpose is so I can measure how long a new hire candidate sits in each step (or status) of the hiring process.目的是让我可以衡量新入职候选人在招聘过程的每个步骤(或状态)中的停留时间。
I've tried writing code to get the macro to start once the workbook opens (module1), and then to loop through the specified range of cells (AC3:AQ5000) once the status in column J is updated using a worksheet_change event (sheet1).我已经尝试编写代码以在工作簿打开(module1)后启动宏,然后在使用 worksheet_change 事件(sheet1)更新列 J 中的状态后循环遍历指定的单元格范围(AC3:AQ5000) . Columns AC through AQ have a formula to date the cell once column J is updated to a status that matches each column (=IF($J5=AC$1,IF(AC5<>"",AC5,TODAY()),""))
.一旦列 J 更新为与每列匹配的状态(=IF($J5=AC$1,IF(AC5<>"",AC5,TODAY()),""))
。 Circular reference has been turned off.循环引用已关闭。
Private Sub Worksheet_change(ByVal Target As Range)
Dim Target As Range
Dim MyCell As Range
Set Target = Sheet1.Range("ac3:aq5000")
For Each MyCell In Target
If MyCell.Value > "" Then
MyCell.Copy
MyCell.PasteSpecial Paste:=x1pasteformats
End If
Next MyCell
End Sub
I expect to get each column to hardcode the date once the cell changes from blank to (today's) date.一旦单元格从空白变为(今天的)日期,我希望让每一列对日期进行硬编码。 So far I receive errors for "ambiguous name detected worksheet_change", "compile error expected identifier", or nothing happens.到目前为止,我收到了“检测到的工作表更改名称不明确”、“编译错误预期标识符”的错误,或者什么也没有发生。
Failed to clearly understand the objective and following are assumed未能清楚地理解目标和以下假设
Range("ac3:aq5000")
instead loop all the headers (row 1) of Column AC to AQ only.如果我假设正确,则无需遍历Range("ac3:aq5000")
所有单元格,而是仅将 AC 列的所有标题(第 1 行)循环到 AQ。 There is also no need to operate any macro in module 1.模块1中也不需要操作任何宏。If the assumed output will be like below如果假设的输出如下所示
Then the code would be simply:那么代码将很简单:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng As Range, cel As Range, col As Long
Set Rng = Intersect(Range("J:J"), Target)
If Not Rng Is Nothing Then
Application.EnableEvents = False
For Each cel In Rng
For col = 29 To 43
If cel.Value <> "" And cel.Value = Cells(1, col).Value Then
Cells(cel.Row, col).Value = Now()
End If
Next
Next cel
Application.EnableEvents = True
End If
End Sub
Please try with following, and change the as per your need请尝试以下操作,并根据您的需要更改
Sub pastespecial()
Dim rangevalue, cellvalue As Range
Set rangevalue = Sheet1.Range("a1:a2")
For Each cellvalue In rangevalue
If cellvalue > "" Then
cellvalue.Copy
cellvalue.pastespecial xlPasteValues
End If
Next cellvalue
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.