麻辣家族討論版版's Archiver

jsc0518 發表於 2017-11-14 07:54

如何移除關鍵字的整列

各位excel vba 先進,

之前我有用下列語法,它可以刪除在A欄出現-->單別:
可以刪除整列
我目前的問題是,若關鍵字-->單別:
若有多很多的空白或添加字,它這一列就會刪除不到
有何與法式可以找到指定後關鍵字,就刪除整列
再麻煩各位,謝謝!



Sub Step3()
'A攔下移除"單別:"
Dim yy
yy = "單別:"
For I = [a65536].End(xlUp).Row To 1 Step -1
If WorksheetFunction.CountIf(Rows(I), yy) > 0 Then Rows(I).Delete
Next I
End Sub

Hsieh 發表於 2017-11-14 10:30

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=101242&ptid=20293]1#[/url] [i]jsc0518[/i] [/b]

Sub ex()
Set a = Columns("A").Find("單別*")
Do Until a Is Nothing
a.EntireRow.Delete
Set a = Columns("A").Find("單別*")
Loop
End Sub

jsc0518 發表於 2017-11-14 11:00

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=101244&ptid=20293]2#[/url] [i]Hsieh[/i] [/b]
Hi 感謝您的回覆,TEST OK
讓我學會了*的用法
謝謝您!

jsc0518 發表於 2022-4-19 21:31

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=101244&ptid=20293]2#[/url] [i]Hsieh[/i] [/b]

Dear Hsieh,
您好!若語法改為B欄列下,當B欄下只要是0的值都移除整列
可是這樣改,連50、60、70、.....都會移除
我只想要等於0才刪除
要如何修改呢?
Thank you.


Sub ex()
Set a = Columns("B").Find("0")
Do Until a Is Nothing
a.EntireRow.Delete
Set a = Columns("B").Find("0")
Loop
End Sub

samwang 發表於 2022-4-20 08:36

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118667&ptid=20293]4#[/url] [i]jsc0518[/i] [/b]

請測試看看,謝謝
Sub test()
Dim xR As Range, xU As Range
For Each xR In ActiveSheet.Range("B:B").SpecialCells(xlCellTypeConstants).Rows
    If Not IsError(Application.Match(0, xR, 0)) Then
        If xU Is Nothing Then Set xU = xR Else Set xU = Union(xR, xU)
     End If
Next
If Not xU Is Nothing Then xU.EntireRow.Delete
End Sub

jsc0518 發表於 2022-4-20 21:42

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118671&ptid=20293]5#[/url] [i]samwang[/i] [/b]
Dear samwang,
Test OK,感謝您的熱心解惑。
與您請教:若需更改關鍵字是否更改下列語法

If Not IsError(Application.Match([color=Red]0[/color], xR, [color=Red]0[/color]))

紅色字的部分改成其他數字或是文字?

samwang 發表於 2022-4-21 06:59

[quote]回復  samwang
Dear samwang,
Test OK,感謝您的熱心解惑。
與您請教:若需更改關鍵字是否更改下列語法 ...
[size=2][color=#999999]jsc0518 發表於 2022-4-20 21:42[/color] [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118675&ptid=20293][img]http://forum.twbts.com/images/common/back.gif[/img][/url][/size][/quote]

可以查一下Excel Math用法就知道了,謝謝

jsc0518 發表於 2022-4-21 22:21

[b]回復 [url=http://forum.twbts.com/redirect.php?goto=findpost&pid=118676&ptid=20293]7#[/url] [i]samwang[/i] [/b]

好的,謝謝您給予的指引,感謝您

頁: [1]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供