首页 > 解决方案 > 关注特定单元格时在特定单元格中添加文本

问题描述

当我在单元格 E18 上有我的“焦点”(所以当我单击此单元格时)时,如何在单元格 C18 中添加文本?在此处搜索其他问题时,我尝试了一些代码组合,但没有任何反应。

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim ws As Worksheet:    Set ws = ThisWorkbook.Worksheets(1)
    Dim myCell As Range:    Set myCell = ws.Range("E18")
    Dim iSect As Range

    Set iSect = Application.Intersect(Target, myCell)

    'If the selection is not your cell, exit sub
    If iSect Is Nothing Then Exit Sub
        Range("$C$18").Value = "HERE IS THE TEXT I WANT"

End Sub

谢谢你的帮助

标签: excelvba

解决方案


这适用于我的工作表。让我知道!

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim trigger As Range
    Set trigger = Range("E18")

    If Intersect(ActiveCell, trigger) Is Nothing Then Exit Sub

    If Not (Intersect(ActiveCell, trigger) Is Nothing) Then
        Range("C18").Value = "Here is the text I want"
    End If

End Sub

推荐阅读