有没有办法使用FIND方法搜索2个替代值中的1个? drop table qtemp.nbrs ;
drop table qtemp.junk ;
drop sequence myseq ;
create table qtemp.nbrs (n int) ;
insert into qtemp.nbrs values(10), (20), (30) ;
create table qtemp.junk (s int, i int) ;
create sequence myseq as integer start with 1 ;
insert into qtemp.junk
select next value for myseq, n from qtemp.nbrs ;
select * from qtemp.junk
; -- report from the above SELECT query follows:
S I
1 10
2 20
3 30
我有3列。 A充满了约会。 B是代码。 D是我需要插入函数的地方。该函数将评估colB中的代码,如果代码是" 2",它将运行FIND方法以在colB中找到最接近的先前代码1或2,然后它将从colA中减去日期两排。例如:
Set d = .Find(What:=[a OR b])
(如果第2行有代码2而不是1,则最后一行会相同)
这是我现在的代码:
A |B ...|D
[date1] |5 |[function does nothing]
[date2] |1 |[function does nothing]
[date3] |3 |[function does nothing]
[date4] |2 |[code 2 found, function inserts result of [date4]-[date2]
答案 0 :(得分:1)
您可以执行两次单独搜索,然后使用Union
功能合并两个Ranges
。 E.g:
Option Explicit
Sub TestUnionFind()
Dim rngSearch1 As Range
Dim rngSearch2 As Range
Dim rngUnionSearch As Range
Set rngSearch1 = Sheet1.Cells.Find(What:="A")
Set rngSearch2 = Sheet1.Cells.Find(What:="B")
Set rngUnionSearch = Union(rngSearch1, rngSearch2)
Debug.Print rngUnionSearch.Address
End Sub
答案 1 :(得分:0)
您必须单独进行每次搜索。
ToShortDateString