我实际上是在尝试编写sumproduct VBA脚本,但我得到了运行时错误...
VBA:
var myApp = angular.module('app', ['ngTouch', 'ui.grid', 'ngSanitize', 'angular-bind-html-compile']);
myApp.controller('getHomeMsg', function($scope, $http, $sce) // prefix function() with ['$scope', '$http', '$sce', ... got the same result
{
$scope.grdAngHomeMsg = {};
$scope.grdAngHomeMsg.columnDefs = [
{
name: 'Subject',
cellTemplate: '<div class="ui-grid-cell-contents" bind-html-compile="COL_FIELD"></div>' //'<div ng-bind-html="row.entity[col.field]"></div>'
},
{
name: 'Message'
},
];
var msgData;
$http(
{
method: 'GET',
url: '/API/HomeMsg',
responseType: 'json'
}).then(function successCallback(response) {
msgData = $scope.grdAngHomeMsg.data = response.data;
$scope.grdAngHomeMsg.data.forEach(function (d) {
$sce.trustAsHtml(d.Subject); // F12 shows d.Subject has value and valid!
});
}, function errorCallback(response, statusText) {
alert(statusText);
});
// also tried replacing this cellTemplate bind-html-compile="COL_FIELD" with ng-bind-html="AA(COL_FIELD)", F12 shows this function is never called
$scope.AA = function (htm) {
return $sc.trustAsHtml(htm);
};
// it never reach here after actual API call
//msgData.forEach(function (d) {
// $sce.trustAsHtml(d.Subject);
//})
}
);
答案 0 :(得分:0)
我没有得到你正在尝试做的事情,但如果(只是一个猜测)你正在尝试评估第14和第15列的SUMPRODUCT
,你可能会想试试这个:
Sub TestEvaluate()
Dim ws As Worksheet, x As String
Set ws = Worksheets(2)
x = Evaluate("sumproduct(" & ws.Columns(14).Address & "," & ws.Columns(15).Address & ")")
MsgBox x
End Sub
答案 1 :(得分:0)
在对另一个答案的评论中,您说您实际上是在尝试使用两个条件(或根据问题的三个条件)进行计数。使用Excel的CountIfs
函数可以更好地实现这一功能,可以使用以下内容在VBA中编码:
Option Explicit
Sub sample_sumpro()
Dim cal_date As Date, nxt_date As Date
Dim name As String
Dim dm_daily As String
cal_date = #12/30/2016#
nxt_date = cal_date + 1
name = "Kawale, Amar"
With Sheets(1)
dm_daily = Application.WorksheetFunction.CountIfs(.Columns(16), name, _
.Columns(4), ">=" & CDbl(cal_date), _
.Columns(4), "<" & CDbl(nxt_date))
End With
MsgBox dm_daily
End Sub