索引并匹配其他条件(仅适用于Excel) [英] Index and match with an additional condition (excel only)
本文介绍了索引并匹配其他条件(仅适用于Excel)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
继续此主题,我想补充一下还有一个条件。我有以下开始
,结束
和操作
列:
Continuing this topic, I would like to add one more condition. I have the following start
, end
, and action
columns:
11/9/2007 10/10/2008 SELL
11/14/2008 5/29/2009 BUY
11/27/2009 2/5/2010 SELL
10/8/2010 4/8/2011 SELL
从2007年4月1日到今天,我还有目标
天(周末除外)。我想执行以下操作:
I also have target
days (ex-weekends) starting from April 1, 2007 to today. I would like to do the following:
- 如果
目标
日在开始
和结束
的范围是
AND操作
是卖出
,然后打印出-1
; - 如果
目标
的日期在开始
和结束
日期
AND操作
为购买
,然后打印1
; - 如果
目标
的天不在开始
和结束
日期,然后打印出0
;
- If the
target
day is in the range ofstart
andend
dates ANDaction
isSELL
, then print out-1
; - If the
target
day is in the range ofstart
andend
dates ANDaction
isBUY
, then print out1
; - If the
target
day is not in the range ofstart
andend
dates, then print out0
;
任何指导/提示都一如既往。
Any guidance/tips appreciated as always.
推荐答案
我认为这段代码将帮助您解决问题
I think this code will help you problem
Dim dStart As Date
Dim dEnd As Date
Dim dDate As Date
Dim iCol As Integer
iCol = 2
Do While Cells(iCol, 2).Value <> ""
dStart = Format(Cells(iCol, 2).Value, "mm/dd/yyyy")
dEnd = Format(Cells(iCol, 3).Value, "mm/dd/yyyy")
if dDate > dStart and dDate < dEnd then
if Cell(iCol,4).Value = "SELL" then
printout -1
else
printout 1
end if
else
printout 0
end if
iCol = iCol + 1
Loop
如果只需要excel功能
If you just only need excel function
=IF(AND(J3 >= F3,J3 <= G3, H3="SELL"),-1,IF(AND(J3 >= F3,J3 <= G3, H3="BUY"),1,0))
这篇关于索引并匹配其他条件(仅适用于Excel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文