excel中用vba找資料

時間 2022-04-09 17:45:12

1樓:匿名使用者

其實find函式本身就可以指定查詢的方式是優先列,還是優先行,通過xlbycolumns表示優先在列中查詢,所以**可以這樣簡化:

sub xx()

dim i as long, rng as range

for i = 2 to [a65536].end(3).row

set rng = [b:c].find(cells(i, "a"),  , , xlwhole, xlbycolumns)

'如果要優先按行查詢,把xlbycolumns改成xlbyrows即可!

if not rng is nothing then

cells(i, "d") = replace(rng.address, "$", "")

else

cells(i, "d") = "無"

end if

next

end sub

詳見附件!

抱歉,cells(i, "a"),   這裡多了乙個逗號 , , xlwhole, xlbycolumns

你去掉乙個逗號後再試試!

2樓:我的王是金閃閃

sub 查詢()

dim i&

for i=2 to [a65536].end(3).row

else

range("d"&i)="無"

end if

next i

end sub

**沒經過測試,測試有問題再追問。

3樓:匿名使用者

sub aa()'e2003通過

rs = [a65536].end(xlup).rowfor i = 2 to rs

v = cells(i, 1)

v1 = "": v2 = ""

for r = 2 to rs

if cells(r, 2) = v then v1 = "b" & r: exit for else _

if cells(r, 3) = v then v2 = "b" & r: exit for

next

if v1 <> "" then cells(i, 4) = v1 else if v2 <> "" then cells(i, 4) = v2 else cells(i, 4) = "無"

next

end sub

在vba裡如何獲取當前工作表裡資料的行數和列數

4樓:匿名使用者

irows=activesheet.usedrange.rows.count

icolumns=activesheet.usedrange.columns.count

'如果**前面的幾行或幾列可能是空的,需要獲得最下面的行數和最右面的列數:

with activesheet.usedrange

iendrow=.rows.count+.row-1

iendcolumn=.columns.count+.column-1

end with

5樓:匿名使用者

sub test1()

a = activecell.row

b = activecell.columnmsgbox a & "行," & b & " 列", vbinformation

end sub

excel怎樣用vba查詢指定內容並返回值

6樓:眯住眼串針

g2輸入公式

=if(left(e2,4)*1=2002,"yes","")下拉對g列進行自動篩選

將篩選結果直接複製貼上到sheet2

刪掉不要的列即可

7樓:匿名使用者

假設圖1在sheet1,圖2在sheet2,請參考

sub test ()

rowcount=sheets(1).[e90000].end(xlup).row

for i =1 to rowcount

if sheets(1).range("e" & i).value like "*2002*" then

sheets(2).range("a" & i).value=sheets(1).range("b" & i).value

sheets(2).range("b" & i).value=sheets(1).range("d" & i).value

end if

next

end sub

8樓:匿名使用者

這個必須用vba?函式就可以輕易做到了啊

怎麼用vba呼叫excel裡的資料?

9樓:

要呼叫某個cell的資料,可以在vba中寫:(假設是b3單元)dim temp as string

...temp = range("b3").value 或 temp = cells(3,2).value 或 temp = cells(3, "b")

這裡,即使excel**裡是數字,到了vba裡面還是變成字串。

然後,再判斷temp的內容,用 if...then... 語句就可以了:

......

if temp = "yes" then

.....

else

if temp = "no" then

.....

else

.....

end if

end if

......

語句不多,好像沒有必要寫乙個sub text()。

10樓:匿名使用者

沒有什麼函式,用if語句:

遍歷整列,if當前單元格="yes"then。。。

if當前單元格="no"then。。。

11樓:太極健

cells是單元格,寫在巨集中即可,還得用上迴圈,具體情況hi我,幫你解決

如何在excel中用巨集(VBA)實現VLOOKUP的功能

慶年工坊 function myvlookup val,rg as range,n as integer,f as boolean arr rg if f then for i ubound arr to 1 step 1if val arr i,1 thenmyvlookup arr i,n en...

excel用vba巨集中用for迴圈將一列滿足條件的後面加上需要的數值比如

直接寫個公式就可以了。假如你那個1在的列是b,在c裡寫公式if b1 1,a 空 然後填充就可以了。如果一定要用vba,那就讀出來單元格的內容,然後根據內容填充就可以了。 姓王的 sub aaa for i 1 to range a65536 end xlup row if cells i,1 張 ...

Excel中VBA如何操作兩個表的資料

楊華山 public sub 複製資料 dim sh1,sh2 as range set sh1 sheets biao1 range a1 a10000 set sh2 sheets biao2 range d1 d10000 sheets biao3 range a1 sheets biao1 ...