|
- Option Explicit
- Sub Test()
- Dim strShName As String
- Dim shFolder As Worksheet, shDoc As Worksheet, objList As Object
- Dim arr As Variant
- Dim lngRow As Long
- Dim strID As String, strList As String, strSplit() As String, strItem As String
- Dim arrKeys As Variant, arrItems As Variant
- Dim Rg As Range
-
- strShName = "FoldersGet"
- Set shFolder = Sheets(strShName)
- Set shDoc = Sheets("Documents")
-
- arr = shFolder.UsedRange
- Set objList = CreateObject("Scripting.Dictionary")
-
- For lngRow = 2 To UBound(arr)
- strID = Trim(arr(lngRow, 5))
- strList = "@" & arr(lngRow, 7) & "@"
- strItem = objList(strID)
- strItem = Replace(strItem, strList, "")
- strItem = strItem & strList
- objList(strID) = strItem
- Next
-
- arrKeys = objList.keys
- arrItems = objList.items
-
- Set Rg = shFolder.Range("O1") '将O列当作来源列
- For lngRow = LBound(arrItems) To UBound(arrItems)
- strItem = arrItems(lngRow)
- strItem = Mid(strItem, 2, Len(strItem) - 2)
- strSplit = Split(strItem, "@@")
- Rg.Resize(UBound(strSplit) + 1, 1) = Application.WorksheetFunction.Transpose(strSplit)
- strID = arrKeys(lngRow)
- strList = "=" & strShName & "!" & Rg.Resize(UBound(strSplit) + 1, 1).Address
- Set Rg = Rg.Offset(UBound(strSplit) + 1, 0)
- objList(strID) = strList
- Next
-
- lngRow = shDoc.Range("C" & Rows.Count).End(xlUp).Row
- arr = shDoc.Range("C1:C" & lngRow)
-
- For lngRow = 2 To UBound(arr)
- strID = Trim(arr(lngRow, 1))
- If strID <> "" Then strList = objList(strID)
- With shDoc.Cells(lngRow, 4).Validation
- .Delete
- .Add Type:=xlValidateList, Formula1:=strList
- End With
- Next
-
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|