vba 根據給定單元格搜尋目標值

2022-04-09 16:27:52 字數 1051 閱讀 8987

sub 德賽()

dim x

dim rng as range

set rng = range("$f$1:$f$1048576") '篩選目標列

if activesheet.autofiltermode = true then '關閉篩選模式

activesheet.autofiltermode = false

end if

rng.autofilter field:=1, criteria1:="=*" & x & "*", operator:=xland '根據給定搜尋條件篩選

for i = 1 to range("a1").currentregion.rows.count '將篩選結果中字串的第8個字元開始連續6個放在第7列

c = worksheets(1).cells(i, 4).value

worksheets(1).cells(i, 7).value = mid(c, 8, 6)

next

with range("g1:g1048576") '篩選結果居中顯示

.horizontalalignment = xlcenter '水平居中baidu

.verticalalignment = xlcenter '垂直zhi居中

end with

''with rng

'.offset(1).resize(.rows.count - 1).specialcells(xlcelltypevisible).copy shift:=xlshiftup

'x = "1013b"

'activesheet.range("$f$1:$f$1048576").autofilter field:=1, criteria1:="=*" & x & "*", operator:=xland

'set rng = range("$f$1:$f$1048576")

'rng.offset(1).specialcells(xlcelltypevisible).delete shift:=xlshiftup

end sub

VBA 定位單元格

在excel自帶功能中,即帶有根據特殊格式定位的功能 開始 查詢與選擇 定位條件 可以根據需要定位查詢 標註 常量 公式 空值 可見單元格 等。該函式和下面excel面板功能相通 其使用格式為 expression.specialcells type,value 下表是value可選的引數 選擇有公...

datagrid 合併指定單元格

1.function mergecells data 合併列的field陣列及對應前提條件filed 為空則直接內容合併 mergefiled 合併列的field名,和premisefiled 合併前邊列的前提條件約束列即只有這個約束列相等時再合併mergefiled列 var dg project...

VSTO如何選定單元格

最近在用vsto做點小東西,乙個意外的錯誤,讓我發現了三種給單元格賦值的方法 前兩種是用range物件,而第三種只用cell即可。先宣告乙個range物件 excel.range xlrange null 一 使用worksheet中的get range 方法。此方法沒有過載,所以選定乙個單元格時特...