这是一个轻微的重复问题,但我相信它可能会简化这种情况。
代码对象:当用户从单元格验证中选择一个条目(即在更改时),代码必须
步骤1到3现在正常运行,第4步不是
当前代码:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ChangedCell As Object
For Each ChangedCell In Target
If ChangedCell.Column = 5 And ChangedCell <> "" Then
Cells(ChangedCell.Row, 8) = Environ("USERNAME")
Cells(ChangedCell.Row, 9) = Format(Now(), "HH:MM:SS")
ChangedCell.Offset(1, 0).EntireRow.Hidden = False
If Cells(ChangedCell.Offset(1, 0), 1).Value <> "HC" Then
ChangedCell.Offset(1, 0).EntireRow.Hidden = False
End If
End If
Next
End Sub
罗布。
答案 0 :(得分:3)
试试这个:
ChangedCell.Offset(1, 0).EntireRow.Hidden = False
N.B:您的代码导致错误的可能原因:显然您无法写入只读值。
已附加问题的附录答案(第4步“显示非用户互动的行”):
Option Explicit
''假设信息(非交互)单元格已合并,这是列E的最后一行。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ChangedCell As Object
Dim last_Row, iter
last_Row = Worksheets("Sheet2").Cells(Rows.count, 5).End(xlUp).Row ''change sheet name if different
For Each ChangedCell In Target
If ChangedCell.Column = 5 And ChangedCell <> "" Then
For iter = 1 To last_Row
ChangedCell.Offset(iter, 0).EntireRow.Hidden = False
On Error GoTo errhand
If ChangedCell.Offset(iter, 0).MergeArea.Address = ChangedCell.Offset(iter, 0).Address Then
On Error GoTo 0
Cells(ChangedCell.Row, 8) = Environ("USERNAME")
Cells(ChangedCell.Row, 9) = Format(Now(), "HH:MM:SS")
'MsgBox ChangedCell.Row
Exit Sub
End If
errhand:
'MsgBox "info row"
Next
End If
Next
End Sub