EXCEl表中,某一单元格满足条件,则另一单元格显示对应内空,用公式怎么写

想在G2中显示,当A列中满足条件为“2017/10/10"时,刚G2显示A列满足条件对应的B列的数据。用什么公式?

如果你的日期是用文本输入的,公式为:=if(A2="2017/10/10",B2,"")
如果你的日期是日期格式,公式为:=if(A2=datevalue("2017-10-10",B2,"")追问

不好意思,做成公式,只能在对应的格里显示,我想要按顺序显示,如上图那样,怎么做?

追答

你这个要用公式的话应该也能做到,但相当烦琐,如果是一次性的操作,我想你肯定是用筛选功能就解决了,如果经常进行这类操作,那么日期肯定也是经常更换,用公式反而不方便,建议你用一个简单的宏
sub 示范()
dim i as integer,n as integer
dim str_date as string
n=2
str_date =inputbox("请输入要查询的日期”)

with sheet1
.range("G2:G10000").clear
for i=2 to .cells(.rows.count,1).end(xlup).row
if cells(i,1)=datevalue(str_date) then
.cells(n,7)=.cells(i,3)
n=n+1
end if
next
end with
end sub

追问

如果不用日期,只用汉字呢?F列只显示满足A列中“是”的对应数据呢?

追答

那样更简单了,那样我建议你在worksheet_change事件中编码,你用一个单元格,比如E2单元格存放“是/否”,事件代码如下:
Private Sub Worksheet_Change(ByVal Target As Range)
dim i as integer,n as integer

If Not Application.Intersect(Target, Range("E2")) Is Nothing And Target.Count = 1 Then
if target = "是" then
n=2
with sheet1
.range("G2:G10000").clear
for i=2 to .cells(.rows.count,1).end(xlup).row
if cells(i,1)="是" then
.cells(n,7)=.cells(i,3)
n=n+1
end if
next
end with
end if
end if
End Sub
这样,你将E2设置数据有效性,只要选“是”,便能得到想要的结果

温馨提示:答案为网友推荐,仅供参考
相似回答