VBA中FIND方法的使用說明zz

2022-06-21 10:00:13 字數 2615 閱讀 6274

find 方法在區域中查詢特定資訊。

語法

表示式.find(what, after, lookin, lookat, searchorder, searchdirection, matchcase, matchbyte, searchformat)

表示式   乙個代表range物件的變數。

引數

名稱必選/可選資料型別描述

what

必選variant

要搜尋的資料。可為字串或任意 microsoft excel 資料型別。

after

可選variant

表示搜尋過程將從其之後開始進行的單元格。此單元格對應於從使用者介面搜尋時的活動單元格的位置。請注意:after 必須是區域中的單個單元格。要記住搜尋是從該單元格之後開始的;直到此方法繞回到此單元格時,才對其進行搜尋。如果不指定該引數,搜尋將從區域的左上角的單元格之後開始。

lookin

可選variant

資訊型別。

lookat

可選variant

可為以下xllookat常量之一:xlwholexlpart

searchorder

可選variant

可為以下xlsearchorder常量之一:xlbyrowsxlbycolumns

searchdirection

可選xlsearchdirection

搜尋的方向。

matchcase

可選variant

如果為true,則搜尋區分大小寫。預設值為false

matchbyte

可選variant

只在已經選擇或安裝了雙位元組語言支援時適用。如果為true,則雙位元組字元只與雙位元組字元匹配。如果為false,則雙位元組字元可與其對等的單位元組字元匹配。

searchformat

可選variant

搜尋的格式。

返回值

乙個range物件,它代表第乙個在其中找到該資訊的單元格。

說明

如果未發現匹配項,則返回nothingfind方法不影響選定區域或當前活動的單元格。

每次使用此方法後,引數 lookin、lookat、searchorder 和 matchbyte 的設定都將被儲存。如果下次呼叫此方法時不指定這些引數的值,就使用儲存的值。設定這些引數將更改「查詢」對話方塊中的設定,如果省略這些引數,更改「查詢」對話方塊中的設定將更改使用的儲存值。要避免出現這一問題,每次使用此方法時請明確設定這些引數。

使用findnextfindprevious方法可重複搜尋。

若要對單元格進行模式更為複雜的搜尋,請結合使用for each...next語句和like運算子。例如,下列**在單元格區域 a1:c5 中搜尋字型名稱以「cour」開始的單元格。當 microsoft excel 找到匹配單元格以後,就將其字型改為 times new roman。

for each c in [a1:c5] if c.font.name like "cour*" then c.font.name = "times new roman" end if next

示例

本示例在第乙個工作表的單元格區域 a1:a500 中查詢包含值 2 的所有單元格,並將這些單元格的值更改為 5。

with worksheets(1).range("a1:a500")

set c = .find(2, lookin:=xlvalues)

if not c is nothing then

firstaddress = c.address

doc.value = 5

set c = .findnext(c)

loop while not c is nothing and c.address <> firstaddress

end if

end with

matlab中find函式的使用說明

find 找到非零元素的索引和值 語法 1.ind find x 2.ind find x,k 3.ind find x,k,first 4.ind find x,k,last 5.row,col find x,6.row,col,v find x,說明 1.ind find x 找出矩陣x中的所有...

matlab中find函式的使用說明

matlab中如何統計乙個矩陣m中零的個數size find m 0 1 原文 find 找到非零元素的索引和值 語法 1.ind find x 2.ind find x,k 3.ind find x,k,first 4.ind find x,k,last 5.row,col find x,6.ro...

find的使用說明與事例

新建歡迎來到來到大浪濤天的部落格!2.1 組合條件 find option 查詢路徑 查詢條件 處理動作 1.1.1 根據檔名查詢 eg find tmp iname fun xargs rm rf regex pattern 以pattern匹配整個檔案路徑字串,而不僅僅是檔名稱 1.1.2 根據...