註冊
登錄
首頁
論壇版規
禁止列表
說明
地圖
數位書香
私人消息 (0)
公共消息 (0)
論壇任務 (0)
系統消息 (0)
好友消息 (0)
帖子消息 (0)
麻辣家族討論版版
»
Excel程式區
» 請教3位數排列組合
返回列表
下一主題
上一主題
發帖
[發問]
請教3位數排列組合
stillfish00
發短消息
加為好友
stillfish00
當前離線
UID
9276
帖子
1018
主題
15
精華
0
積分
1058
金錢
1058
點名
0
作業系統
win7 32bit
軟體版本
Office 2016 64-bit
閱讀權限
50
性別
男
來自
桃園
在線時間
1141 小時
註冊時間
2012-5-9
最後登錄
2022-9-28
大學生
帖子
1018
主題
15
精華
0
積分
1058
點名
0
作業系統
win7 32bit
軟體版本
Office 2016 64-bit
閱讀權限
50
性別
男
來自
桃園
註冊時間
2012-5-9
最後登錄
2022-9-28
1
#
跳轉到
»
發表於 2019-2-21 13:45
|
顯示全部帖子
本帖最後由 stillfish00 於 2019-2-21 13:53 編輯
回復
1#
eric7765
任意位數排列
Sub Solution()
Range(Cells(2, "D"), Cells(Rows.Count, "E")).ClearContents ' Clear result
If Cells(Rows.Count, "A").End(xlUp).Row < 2 Then Exit Sub ' Exit if no input
Dim text As String, id, r
r = 1
For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
text = Cells(i, "A").text
id = Cells(i, "B").Value
If Len(text) > 0 Then
For Each s In GetAllPermutation(text)
r = r + 1
Cells(r, "D").Value = s
Cells(r, "E").Value = id
Next
End If
Next
End Sub
複製代碼
Function GetAllPermutation(ansi_str As String)
Dim ans: Set ans = CreateObject("scripting.dictionary")
Dim ch, new_ans
ans("") = 0
For i = 1 To Len(ansi_str)
ch = Mid(ansi_str, i, 1)
Set new_ans = CreateObject("scripting.dictionary")
For Each s In ans.keys()
For j = 0 To Len(s)
new_ans(Left(s, j) & ch & Mid(s, j + 1)) = 0
Next
Next
Set ans = new_ans
Next
GetAllPermutation = ans.keys()
End Function
複製代碼
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。
TOP
stillfish00
發短消息
加為好友
stillfish00
當前離線
UID
9276
帖子
1018
主題
15
精華
0
積分
1058
金錢
1058
點名
0
作業系統
win7 32bit
軟體版本
Office 2016 64-bit
閱讀權限
50
性別
男
來自
桃園
在線時間
1141 小時
註冊時間
2012-5-9
最後登錄
2022-9-28
大學生
帖子
1018
主題
15
精華
0
積分
1058
點名
0
作業系統
win7 32bit
軟體版本
Office 2016 64-bit
閱讀權限
50
性別
男
來自
桃園
註冊時間
2012-5-9
最後登錄
2022-9-28
2
#
發表於 2019-3-7 17:24
|
顯示全部帖子
回復
7#
eric7765
C欄中 如果有任意字再進行排列
Sub Solution()
Range(Cells(2, "D"), Cells(Rows.Count, "E")).ClearContents ' Clear result
If Cells(Rows.Count, "A").End(xlUp).Row < 2 Then Exit Sub ' Exit if no input
Dim text As String, id, r
r = 1
For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
text = Cells(i, "A").text
id = Cells(i, "B").Value
If Len(text) > 0 Then
If Len(Cells(i, "C").text) > 0 Then
For Each s In GetAllPermutation(text)
r = r + 1
Cells(r, "D").Value = s
Cells(r, "E").Value = id
Next
Else
r = r + 1
Cells(r, "D").Value = text
Cells(r, "E").Value = id
End If
End If
Next
End Sub
Function GetAllPermutation(ansi_str As String)
Dim ans: Set ans = CreateObject("scripting.dictionary")
Dim ch, new_ans
ans("") = 0
For i = 1 To Len(ansi_str)
ch = Mid(ansi_str, i, 1)
Set new_ans = CreateObject("scripting.dictionary")
For Each s In ans.keys()
For j = 0 To Len(s)
new_ans(Left(s, j) & ch & Mid(s, j + 1)) = 0
Next
Next
Set ans = new_ans
Next
GetAllPermutation = ans.keys()
End Function
複製代碼
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。
TOP
靜思自在 :
一句溫暖的話,就像往別人身上灑香水,自己會沾到兩三滴。
返回列表
下一主題
上一主題
EXCEL專屬討論區
Excelㄧ般區
Excel程式區
進階應用專區
OFFICE 系列
Word
PowerPoint
Access
Office不分區
程式語言
VB 與 VB.Net
C 與 C#
Java 與 J#
程式設計不分區
資料庫
ORACLE
My SQL
MS SQL
網頁設計
ASP 與 ASP.NET
PHP
PHP+MySQL 入門實作
JavaScript
FLASH / ActionScript
HTM/ HTML/ CSS
網頁設計不分區
電腦與作業系統
電腦各種硬體討論
一般電腦軟體討論
論壇事務
管理公告
投訴反映
新手測試
愛 • 生活
公益佈告欄
生活與感動
[收藏此主題]
[關注此主題的新回復]
[通過 QQ、MSN 分享給朋友]
申請友情鏈接
Facebook粉絲