答案1
我想用列标题中的日期替换所有“x”值。
Sub MyReplace()
Dim OneCell As Range
For Each OneCell In ActiveSheet.UsedRange
If OneCell.Column > 1 And OneCell.Row > 1 Then
If OneCell.Value = "x" Then
OneCell.Value = OneCell.EntireColumn.Cells(1, 1).Value
End If
End If
Next
End Sub
每次改变值时都会自动运行,无需单击任何按钮。
Dim flag As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
Dim OneCell As Range
If flag Then Exit Sub
flag = True
For Each OneCell In Target
If OneCell.Column > 1 And OneCell.Row > 1 Then
If OneCell.Value = "x" Then
OneCell.Value = OneCell.EntireColumn.Cells(1, 1).Value
End If
End If
Next
flag = False
End Sub