在单个工作表中连接多个宏

时间:2018-01-05 14:08:38

标签: excel vba excel-vba

我正在尝试编码日期更改,如果修改了一个单元格,并且整合了一个ALL CAPS文本。我有更改日期的工作,但似乎无法弄清楚我所缺少的是为了让ALL CAPS正常工作。

Private Sub Worksheet_Change(ByVal Target As Range)
'Fill in Date.
Dim WorkRng As Range
Dim Rng As Range
Dim xOffsetColumn As Integer
Set WorkRng = Intersect(Application.ActiveSheet.Range("J:J"), Target)
xOffsetColumn = 20
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng In WorkRng
    If Not VBA.IsEmpty(Rng.Value) Then
        Rng.Offset(0, xOffsetColumn).Value = Now
        Rng.Offset(0, xOffsetColumn).NumberFormat = "dd-mm-yyyy, hh:mm:ss"
    Else
        Rng.Offset(0, xOffsetColumn).ClearContents
    End If
Next
Application.EnableEvents = True
End If
Else If
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
' Loop to cycle through each cell in the specified range.
For Each x In Range("A10:D1000,G10:J1000,T10:T1000")
  ' Change the text in the range to uppercase letters.
  x.Value = UCase(x.Value)
Next
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub

1 个答案:

答案 0 :(得分:0)

您需要访问范围内的单元格。

For Each cell In Range("A10:D1000,G10:J1000,T10:T1000").Cells
  ' Change the text in the range to uppercase letters.
  cell.Value = UCase(cell.Value)
Next