0
這是整個代碼,以防您想要查看它:https://pastebin.com/TbewRRCc。我的問題是,檢查後,我的集合確實只包含我想要的列。所以,如果我有三列我想在那裏,columnsToCopy.Count將= 3,當我只是複製columnToCopy(3)。複製結果將只是一列。但是當我通過循環來創建這三列的聯合時,這些列之間的所有列也將在聯合中。聯盟正在抓住我的選擇之間的所有範圍
例如。假設我正在複製第1列,第13和第30列。粘貼表格將是從1到30的所有列。這不是我想要的。我只想要列1,13,和30 ...所以這三個列總共爲這個特殊的Colelction。
關於什麼可能會導致我的問題,以及如何解決它的任何想法?
For arrayLoop = LBound(iq_Array) To UBound(iq_Array)
' Take copy of potential ref and adjust to standard if required
checkStr = iq_Array(arrayLoop)
If hasIQs And Left(checkStr, 3) <> "iq_" Then checkStr = "iq_" & checkStr
' Look for existence of corresponding column in local copy array
pCol = 0
For iCol = 2 To colNumb
If checkStr = IQRef(iCol) Then
pCol = iCol
Exit For
End If
Next iCol
If pCol > 0 Then
' Paste the corresponding column into the forming table
columnsToCopy.Add ShRef.Columns(pCol).EntireColumn
End If
Next arrayLoop
If columnsToCopy.Count > 1 Then 'data was added
' Copy table
Dim unionVariable As Range
Set unionVariable = columnsToCopy(1)
For k = 1 To columnsToCopy.Count
Set unionVariable = xlApp.Union(unionVariable, columnsToCopy(k))
Next k
unionVariable.Copy
Next k
unionVariable.Copy
所以你說當你粘貼它只粘貼3列?第1,3,5列?我真的不明白爲什麼它不適合我......我能上傳我正在使用的文件,這樣你就可以看到我在說什麼了嗎? – Pinlop
[PPT幻燈片病毒掃描](https://www.virustotal.com/#/file/ff5125e3234eb4795dbd330be554dbc90197eafb60cea1cf036da9389a92165f/detection),[Excel文件病毒掃描](https://www.virustotal.com/#/file/24d41c015f53fe0621d91a0db8661701b6e858e98edc9e961f703e1da8706a58/檢測),[PPT幻燈片文件](https://filetea.me/n3wZluzhVXFTpmjlUPmTxzKew),[Excel文件](https://filetea.me/n3wG3zbxnKoRuuYhonhFf7PHQ) – Pinlop