本文介绍了以前活跃的细胞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我正在编写的代码,我将监视某些单元格范围中的更改以运行函数和私有子代。为此,我在worksheet_change子文件中使用相交函数。



然而,相交测试的触发器总是我移出单元格测试是否通过鼠标移动到不同的单元格或通过游标移动。



我需要的是一种定义一个变量的方法,该变量包含



我尝试过下面的代码,但我所得到的只是错误。



任何人都有这样的想法?

 公开xfrLastCell As String 
公开xfrActiveCell As String

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

如果xfrActiveCell =然后xfrActiveCell = ActiveCell.Address
xfrLastCell = xfrActiveCell
xfrActiveCell = ActiveCell
MsgBox xfrLastCell

End Sub

谢谢你们

解决方案

使用此代码,参考 Pr eviousActiveCell 将返回所需的结果:

 公开PreviousActiveCell为范围

私人Sub Worksheet_SelectionChange(ByVal Target As Range)
静态p前一个范围
设置PreviousActiveCell = pPrevious
设置pPrevious = ActiveCell
End Sub
/ pre>

这可以在单个工作表中工作。您是否需要其他工作表和工作簿上的上一个单元格?


For the code I am writing I monitor the changes in certain cell ranges to run functions and private subs. For this I use the Intersect function in the worksheet_change sub.

However, the trigger for the intersect 'test' is always that I 'move out' of the cell I am testing for whether it'd be via mouseclick into a different cell or via cursor move.

What I need is a way to define a variable which contains the .address of the cell I had selected before.

I tried the code below, but all I get is errors.

Does anybody have an idea how to do this?

Public xfrLastCell As String
Public xfrActiveCell As String

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If xfrActiveCell = "" Then xfrActiveCell = ActiveCell.Address
xfrLastCell = xfrActiveCell
xfrActiveCell = ActiveCell
MsgBox xfrLastCell

End Sub

Thank you all

解决方案

With this code, referring PreviousActiveCell will return desired result:

Public PreviousActiveCell as Range

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Static pPrevious as Range
    Set PreviousActiveCell = pPrevious
    Set pPrevious = ActiveCell
End Sub

This works inside single worksheet. Do you need a previous cell across other sheets and workbooks?

这篇关于以前活跃的细胞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 05:28