Yamasaki450
Board Regular
- Joined
- Oct 22, 2021
- Messages
- 71
- Office Version
- 2021
- Platform
- Windows
Sub Yamasaki450_1()
Dim i As Long, j As Long, k As Long
Dim va, vb
Dim c As Range
Dim t As Double
t = Timer
Set c = Range("B2:D15") 'change the range to suit
va = c
ReDim vb(1 To UBound(va, 1), 1 To UBound(va, 2))
For j = 1 To UBound(va, 2)
k = UBound(va, 1)
For i = UBound(va, 1) To 1 Step -1
If va(i, j) <> Empty Then
vb(k, j) = va(i, j)
k = k - 1
End If
Next
Next
c = vb
Debug.Print "Completion time: " & Format(Timer - t, "0.00") & " seconds"
End Sub
I tried this code and its really fast it only takes a minute to sort 15 million cells... But all cells with value 0 are missing... Is this possible to fix?Try this on a copy of your data:
VBA Code:Sub Yamasaki450_1() Dim i As Long, j As Long, k As Long Dim va, vb Dim c As Range Dim t As Double t = Timer Set c = Range("B2:D15") 'change the range to suit va = c ReDim vb(1 To UBound(va, 1), 1 To UBound(va, 2)) For j = 1 To UBound(va, 2) k = UBound(va, 1) For i = UBound(va, 1) To 1 Step -1 If va(i, j) <> Empty Then vb(k, j) = va(i, j) k = k - 1 End If Next Next c = vb Debug.Print "Completion time: " & Format(Timer - t, "0.00") & " seconds" End Sub
Yes i did try your code but there i asked you to extend existing code. Your code works just fine but i still need separate code for sorting and separate for highlighting cells. I will open new thread for this...Did you try the code in post #19 on VBA macro to delete highlighted cells
Ah, sorry about that.But all cells with value 0 are missing... Is this possible to fix?
If va(i, j) <> Empty Then
to If va(i, j) <> "" Then
Sub Yamasaki450_2()
Dim i As Long, j As Long, k As Long
Dim va, vb
Dim c As Range
Dim t As Double
t = Timer
Set c = Range("B2:D15") 'change the range to suit
va = c
ReDim vb(1 To UBound(va, 1), 1 To UBound(va, 2))
For j = 1 To UBound(va, 2)
k = UBound(va, 1)
For i = UBound(va, 1) To 1 Step -1
If va(i, j) <> "" Then
vb(k, j) = va(i, j)
k = k - 1
End If
Next
Next
c = vb
Debug.Print "Completion time: " & Format(Timer - t, "0.00") & " seconds"
End Sub
Now it works. Thanks a lot for your help man... Great support on this forum...Ah, sorry about that.
We need to changeIf va(i, j) <> Empty Then
toIf va(i, j) <> "" Then