簡體   English   中英

使用行號和列號更新單元格值,以根據選擇的單元格在間接函數中使用

[英]Update a cell value with Row and Column number for use in indirect function based on which cell is selected

嗨,我有一個類似於以下的電子表格

電子表格

單擊單元格(紅色單元格)時,我想將行和列號返回到另一個單元格以進行間接查找(藍色單元格)

理想情況下,我只想更新單元格值(如果它在設置范圍內),或者至少將其限制為僅用於工作表以進行錯誤處理。

希望這很清楚...對Google而言並非易事。 我的實驗

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    MsgBox ActiveCell.Row
End Sub

即使宏運行正常,也什么也沒返回,甚至沒有消息框。 有任何想法嗎?

根據您的示例。 確保您的代碼在適當的工作表模塊中,而不是在標准模塊中,並確保Application.EnableEvents = True(您現有的代碼應已執行某項操作)。

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

If Intersect(Target(1), Range("C4:H9")) Is Nothing Then Exit Sub

Range("J3").Value = Cells(Target(1).Row, 2) & "," & Cells(3, Target(1).Column)

End Sub

在工作表的專用代碼表中使用它。

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Not Intersect(Target.Cells(1), Range("C4:H9")) Is Nothing Then
        Range("C4:H9").Interior.Pattern = xlNone
        Cells(3, "J") = Join(Array(Cells(Target.Cells(1).Row, "B"), _
                                   Cells(3, Target.Cells(1).Column)), Chr(44))
        Target.Cells(1).Interior.ColorIndex = 3
    End If
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM