VBA SumIfs不适用于日期范围 [英] VBA SumIfs not working with Date range
本文介绍了VBA SumIfs不适用于日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我尝试了许多变体,但无法完成这项工作:
So, I have tried many variations, but I can't make this work:
var_sum = WorksheetFunction.SumIfs(Range("H:H"), Range("B:B"), str_client, Range("A:A"), "<=" & date_var)
此公式有2个条件.第二个(日期比较)将其破坏并使总和= 0.date_var是一个Date变量.Excel中的日期范围格式为日期.
This formula has 2 conditions. The second one (date comparison) breaks it and makes the sum = 0. date_var is a Date variable. The date range in Excel is formatted as Date.
有什么问题吗?
推荐答案
我觉得您的日期带有字符串.
I have a feeling you have a string with the date.
Date_Var = "01/01/2013"
您可以尝试使用 CDate(
或 CLng(
)将其转换为适当的值,因为Excel将日期存储为1900年1月1日以后的天数
you could try using CDate(
or CLng(
to convert it to the appropriate value, as Excel stores dates as number of days past Jan 1, 1900
var_sum = WorksheetFunction.SumIfs(Range("H:H"), Range("B:B"), str_client, _
Range("A:A"), "<=" & CLng(date_var))
这篇关于VBA SumIfs不适用于日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文