我有一個非常大的工作表,大約有150列,其中大部分都包含公式。當我想將我輸入的數據排序到不使用公式的單元格時,會混淆整個表單。 - 輸入單元不在一起VBA僅對文本進行排序,忽略具有公式的單元格
目前,我在VBA中的解決方案是將單元複製到另一個(隱藏)表單中,並將其全部歸併。我只是覺得這對於一個看起來很簡單的任務來說太麻煩了。有沒有更聰明的方法來解決這個問題?
編輯
QUA @varocarbas我曾嘗試下面的代碼:
Private Sub sortInputButton_Click()
' This sub sorts the inpur, without messing up the references [hopefully]
Dim rowCount As Integer
Dim colCount As Integer
rowCount = countItems
colCount = 180
Dim inputRange As Range
Set inputRange = Sheets("Input").Range("A3")
Set inputRange = inputRange.Resize(rowCount, colCount)
Dim targetRange As Range
On Error Resume Next ' If range is nothing, throws an error - we don't want that
Set targetRange = inputRange.SpecialCells(xlCellTypeConstants)
On Error GoTo 0
If targetRange.Cells.count > 0 Then
Sheets("Input").Select
targetRange.Select
Call targetRange.Sort(Sheets("Input").Range("A3"), xlAscending)
End If
End Sub
但是,這給我的錯誤the command you chose cannot be performed with multiple selections. Select a single range and click the command again.
這似乎起初工作 - 但我發現它只在我輸入詳細信息之前有效。然後我得到這個錯誤:'你選擇的命令不能執行多個選擇。選擇一個範圍,然後再次點擊該命令。' 我有6個用戶輸入數據單元格,然後是20x'[formula] [input]',後面跟着更多。我的觀點是輸入和公式是混合的。 – Kentora
@Kentora我不理解問題。你能否用你試過的代碼更新你的問題,以便我可以幫忙?這個解決方案應該沒有任何限制。 – varocarbas
@Kentora另外,我包含了一個錯誤捕獲,因此無論如何它都不能輸出錯誤(在最壞的情況下它不會工作)。 – varocarbas