English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

A1至A100的儲存格
分別放入的值
為1至100
請問我要將
2,3,6,11,14,15,17,22,27,33,99
保留
其餘作刪除
請問程式碼要如何寫呢?
謝謝

2006-05-25 13:11:50 · 3 個解答 · 發問者 strike 5 in 電腦與網際網路 軟體

3 個解答

Sub AA()
a = 1
Do While Cells(a, 1) <> ""
b = Cells(a, 1)
If b = 2 Or b = 3 Or b = 6 Or b = 11 Or b = 14 Or b = 15 Or b = 17 Or b = 22 Or b = 27 Or b = 33 Or b = 99 Then
Else: Cells(a, 1).Clear
End If
a = a + 1
If a = 101 Then Exit Sub
Loop
End Sub

2006-05-26 13:35:03 · answer #1 · answered by ? 2 · 0 0

pj 兄的<>應該要改成=才對吧
這樣會比較簡捷些
If InStr("02,03,06,11,14,15,17,22,27,33,99", Format(Cells(i, 1), "00")) > 0 Then

2006-05-25 15:16:04 · answer #2 · answered by EH 5 · 0 0

usedRows = Worksheets("sheet1").UsedRange.Rows.Count
For i = 1 To usedRows
If (Worksheets("sheet1").Cells(i, 1) <> 2 Or (Worksheets("sheet1").Cells(i, 1) <> 3) Or (Worksheets("sheet1").Cells(i, 1) <> 6) Or (Worksheets("sheet1").Cells(i, 1) <> 11) Or (Worksheets("sheet1").Cells(i, 1) <> 14) Or (Worksheets("sheet1").Cells(i, 1) <> 15) Or (Worksheets("sheet1").Cells(i, 1) <> 17) Or (Worksheets("sheet1").Cells(i, 1) <> 22) Or (Worksheets("sheet1").Cells(i, 1) <> 27) Or (Worksheets("sheet1").Cells(i, 1) <> 33) Or (Worksheets("sheet1").Cells(i, 1) <> 99)) Then
Worksheets("sheet1").Cells(i, 1) = Worksheets("sheet1").Cells(i, 1)
Else
Worksheets("sheet1").Cells(i, 1) = ""
End If
Next
這個笨方法 解決將2,3,6,11,14,15,17,22,27,33,99保留其餘作刪除 的問題
參考看看

2006-05-29 10:43:06 補充:
感謝a8350070 兄 指正呵呵 真的寫錯了 因為我沒測試 寫好一個條件就狂複製 所以累贅了點

2006-05-25 13:33:32 · answer #3 · answered by pj 2 · 0 0

fedest.com, questions and answers