我有一个VBA来计算COLORED CELLS的数量。 VBA模块与单元格对齐。但是,该功能仅在我单击单元格功能并按ENTER时运行。更改单元格值不会自动运行该功能。 公式的自动更新也在选项中启用。
这是我的VBA:
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function

我正在使用工作表命令调用此模块:= ColorFunction(J70,$ B $ 3:$ BV $ 66)
任何帮助? 感谢名单
答案 0 :(得分:0)
你可以使用一点解决方法
在相关的表格代码窗格中放置以下代码
UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPress:)];
[self.myTableview addGestureRecognizer:longPressRecognizer];
-(void)onLongPress:(UILongPressGestureRecognizer*)pGesture
{
if (pGesture.state == UIGestureRecognizerStateRecognized)
{
//Do something to tell the user!
}
if (pGesture.state == UIGestureRecognizerStateEnded)
{
CGPoint p = [pGesture locationInView:self.myTableview];
NSIndexPath *indexPath = [self.myTableview indexPathForRowAtPoint:p];
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if ([touch.view isDescendantOfView:self.myTableview]) {
// Don't let selections of auto-complete entries fire the
// gesture recognizer
return NO;
}
return YES;
}
这将在用户拥有以下内容后实际触发所有Option Explicit
Dim myColor As Long '<--| variable to store the "preceeding" color
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim coloredRng As Range
If myColor > 0 Then '<--| if a "colored" cell had been selected in the "preceeding" selection, then store its color
Me.Calculate '<--| trigger calculation and, by its effects, all functions with 'Application.Volatile'
myColor = 0 '<--| reset "preceeding" color to zero. it'll be set to a vaild color if user has currently selected a "colored" cell
End If
Set coloredRng = Range("J70:J73") '<--| set the range whose color change must "trigger" 'ColorFunction()' (change "J70:J73" to your actual "colored" cells addresses)
If Not Intersect(Target, coloredRng) Is Nothing Then myColor = Target.Interior.Color '<--| if current selection belongs to the "colored" range then store its color to trigger 'ColorFunction()' cells as soon as the user leaves the current selection
End Sub
功能:
更改有效单元格的颜色(您在ColorFunction()
中列出的单位之一)
离开更改的彩色单元格
因此,您会遇到一点延迟,但它会工作
答案 1 :(得分:-1)