我想读取列“预测”(BM)到列D的最新值,我写了下面的代码,但它没有给我正确的值。例如,我有列AV 21 - 0.5的最新值作为我的结果。
Option Explicit
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column <> 9 Then Exit Sub
Dim foundCell As Range: Set foundCell = Cells(Target.Row, "I").End(xlToLeft)
Target.Offset(, 1).Value = foundCell.Value
Target.Offset(, 2).Value = Cells(1, foundCell.Column).Value
End Sub
Public Sub LoopCells()
Dim c As Range
Dim rngSearch As Range
Dim rngFind As Range
Set rngFind = ActiveSheet.Range("A1:K15")
For Each c In rngFind
If c.Value = "Forecast" Then
MsgBox "FindMe found at " & c.Address
Set rngSearch = ActiveSheet.Range("A1:" & c.Address)
'Set LastCell = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious)
' MsgBox LastCell
Dim d As Range
For Each d In rngSearch 'Range("strFirstAddress:A1").Cells
If d.Value > 0 Then
MsgBox foundCell
Exit For
End If
Next
MsgBox foundCell
MsgBox "The first value greater than zero is in cell " & firstAddress & _
"; - it has value " & firstValue
End If
Next c
End Sub
1条答案
按热度按时间zfciruhq1#
下面是一个可能有帮助的快速示例(基于
beforeDoubleClick
,但应说明如何利用foundCell
):测试信息:
![](https://i.stack.imgur.com/2qA6g.png)
请注意,“I”是第9列,我只是想快速检查一下,如果我不小心双击了其他地方,是否不想开始运行。