excel searching technique 2

2011-03-21 8:22 pm
please refer to
http://hk.knowledge.yahoo.com/question/question?qid=7011032001585

如果我想找出以1 1 1 2 2 1為基礎的組合,即

* 1 1 2 2 1
1 * 1 2 2 1
1 1 * 2 2 1
1 1 1 * 2 1
1 1 1 2 * 1
1 1 1 2 2 *


* 為 1,2,3

可以提供code 嗎?我自己想到是用for loop,但我想不到怎麼改d 星星@@“。。。

回答 (2)

2011-03-22 4:20 am
✔ 最佳答案
我以 procedure SmartFilter 已經 get ready 為基礎, extend 多一個 upper level procedure Combination。

不過 SmartFilter 都需要作出相應修改:

Sub SmartFilter()
改為: Sub SmartFilter(haha)

Delete 呢行: haha = InputBox(....

Sub Combination()
Dim wahaha, InputTarget, CheckPass, CombLoop
wahaha = InputBox(....
CheckPass = "Back"
Do
CombLoop = CombLoop + 1
InputTarget = ""
Do
If Len(InputTarget) + 1 = CombLoop Then
InputTarget = InputTarget & "?"
Else
InputTarget = InputTarget & Mid(wahaha, Len(InputTarget) + 1, 1)
End If
Loop Until Len(InputTarget) = Len(wahaha)
SmartFilter (InputTarget)
If CombLoop = Len(wahaha) Then
CheckPass = "Go"
End If
Loop Until CheckPass = "Go"
End Sub

2011-03-23 10:59:39 補充:
15 個位? 我相信你已化成另一 output 模式, 你唔會真係想將咁大份數據繼續以 display 形式顯示出嚟呱…??

2011-03-23 13:13:14 補充:
我 debug 過 MsgBox Prompt text 係有 limit 嘅, 當你自己定好點 output, …

Dim Result 由 procedure SmartFilter 改去 Combination;

喺 SmartFilter 度移走:
Result = "The found …

wahaha = InputBox(…
>>喺 Combination 呢度插入
CheckPass = …

喺 SmartFilter 度移走:
Response = MsgBox(…

Loop Until CheckPass…
>>喺 Combination 呢度插入
End Sub

2011-03-23 13:23:26 補充:
另外 ByVal/ByRef 同 Dim 乜乜嘅 As 相同道理, 唔打一律當 ByRef, 你都見個 procedure 係 work 嘅, 效率問題, 小型 VBA 運算可以不理。

2011-03-23 20:19:14 補充:
我都唔記得將所有 Dim set 哂喺 General 度 (Sub procedure 上面)… 尤其是 SourceRange, 不過你個 case 應該係 Result = "The found … 嗰句 location 嘅問題, 我 run step into 往返兩個 procedures, Result 嘅內容一如我所設計嘅一樣, 並無錯誤。

2011-03-24 00:09:51 補充:
以上講咗, Dim 晒所有 variables 去 General 度, Dim 有分 General 同 inside procedures。 Dim under General 令同名 variables 喺不同 procedures 仍然一致同有連繫, 否則就算你喺 procedures 內裡 Dim 咗, 同名嘅 variables 會喺各 procedures 內獨立運算:

2011-03-24 00:10:21 補充:
取消晒所有 procedures 內嘅 Dim variables, 再喺第一個 procedure 上面 Dim 晒各 variables。

Dim wahaha, InputTarget, CheckPass, CombLoop, Result, FirstAddress, Response

Sub Combin...

2011-03-24 01:44:20 補充:
這方面我也不太了解, 我也發現同樣問題, ran 一次後如不把 Excel 整個關掉, 連續第二次就會 loop 死, 但只要喺主程式 (選擇要 run 嗰個) End Sub 前加多個 End, 就可解決。
Sub Combin…

End <<<< end 晒 VBA
End Sub
2011-03-24 8:51 am
i somehow did it! thanks a lot!!!
i misunderstand that you are meaning...

2011-03-24 00:51:21 補充:
sub combination
dim a,s,d,f,g,h
end sub

sub smartfilter(xx)
end sub
as i try it before, it can't works.

2011-03-24 00:51:32 補充:
however, another problem appear=[. 我只可以run一次,run第二次他會好像loop死了一般沒反應,我要ctrl+alt+del才可以break the sub,and said...
==========
執行階段錯誤'-214741848(80010108)'

Automation錯誤
用戶端中斷已啟動物件的連線。
===========
我program 經驗淺,但也是第一次出現"program只能run一次(without closing the file)"的情況,小nick知道是什麼原因嗎?


收錄日期: 2021-04-16 12:24:42
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20110321000051KK00368

檢視 Wayback Machine 備份