1樓:萬年金剛鑽
const crange = "a1:c3", csheet = "sheet1"
private sub deletemult()
dim arr as variant
dim rc, rt as range
dim sr as string, i as integer
set rt = sheets(csheet).range(crange)
for each rc in rt
if instr(rc, "-") > 0 then
arr = split(rc, "-")
sr = ""
for i = 0 to ubound(arr)
if len(trim(arr(i))) = 1 then sr = sr & "-" & trim(arr(i))
next
sheets(csheet).range(rc.address) = right(sr, len(sr) - 1)
erase arr
end if
next
end sub
2樓:
傳一個供你參考,是一個自定義函式,使用方法就跟使用excel的普通函式一樣。輸入一個函式後,向下拖動複製公式即可。單函式的適用範圍更廣。
效果圖如下:(附件裡有**,我用的是excel2010,另存了一個excel2003格式)
3樓:匿名使用者
sub aa()
dim s_col, e_col, s_row, e_row as integer
dim i, l, c_len, ii1, ll1 as integer
dim ss as string
s_col = 2 ' col b
e_col = 4 ' col d
s_row = 5 ' row 5
e_row = 10 'row 10
'msgbox sheet1.cells(5, 2).value
for i = s_col to e_col
for l = s_row to e_row
ss = ""
ii = 0
ll1 = 1
c_len = len(sheet1.cells(l, i).value)
for ii1 = 1 to c_len
if mid(sheet1.cells(l, i).value, ii1, 1) = "-" then
if (ii < 2) then
if ss <> "" then
ss = ss & "-" & mid(sheet1.cells(l, i).value, ll1, ii)
else
ss = ss & mid(sheet1.cells(l, i).value, ll1, ii)
end if
end if
ii = 0
ll1 = ii1 + 1
else
ii = ii + 1
end if
next ii1
if (ii < 2) then
ss = ss & mid(sheet1.cells(l, i).value, ll1, ii)
end if
sheet1.cells(l, i + 5).value = ss
'msgbox "l=" & cstr(l) & " i=" & cstr(i) & " " & ss
next l
next i
end sub
excel vba 刪除指定字元
4樓:微微一笑回
sub 刪除字元()
arr = [c2:h20]
set regex = createobject("vbscript.regexp")
regex.global = true
regex.pattern = "[,。@#$%&]+"
for i = 1 to ubound(arr)for j = 1 to ubound(arr, 2)arr(i, j) = regex.replace(arr(i, j), "/")
next
next
[c2:h20] = arr
end sub
excel vba刪除特殊符號
5樓:陽光上的橋
第一步、複製你需要刪除的特殊符號,滑鼠雙擊單元格,只複製需要刪除的部分內容
第二步、按ctrl+h,或者選擇選單裡面的替換,查詢內容處貼上你剛才複製的內容,替換為保留為空,選擇全部替換
6樓:匿名使用者
sub 去除特殊字元()
dim n, txarr, tx_s, tx_asc, s, c, new_s
n = 100 '處理的最大行數,可更改
tx_s = "#,*,%,&" '特殊字元,可增加txarr = split(tx_s, ",")tx_asc = ","
for i = 0 to ubound(txarr)tx_asc = tx_asc & asc(txarr(i)) & ","
next
for i = 1 to n
new_s = ""
s = cells(i, 1).valuefor j = 1 to len(s)
c = mid(s, j, 1)
if instr(tx_asc, "," & asc(c) & ",") = 0 then
new_s = new_s & c
end if
next
cells(i, 1).value = new_snext
end sub
檔案如何程式設計批量刪除含某些字元的字串
windows的自帶的記事本,復開啟制txt,在選單 編輯 替換 bai 將要去掉的字元輸出查詢內容這du一zhi欄dao,替換為這一欄不填,就能把這些去掉。同樣在word裡也可以,用word開啟txt,在編輯中也有替換這個功能。如果要刪除檔案中所有這樣的,可以在word中開啟這個檔案,進入替換功能...
編寫程式,將字串s中的所有字元c刪除
1.幾乎所有頭函式需要 include因為專案包括輸出和輸入字串和專字元,h include 字串 2.第二種方法是 屬定義變數的性格 100 儲存相同大小的兩個字串。1 整數變數intc inti 0,j 0 代表一個字串。b 100 表示刪除對應字元的字串,整數c表示要刪回除的位。ji是for迴...
編寫程式刪除字串中下標為偶數的所有字元,將剩餘字元組成新字串輸出
include include using namespace std void stringproc char s void main strcpy s,tmp delete tmp include void main printf 0 請編寫一個程式,其功能是 從鍵盤輸入字串,將字串中下標位偶數...