teodormircea
Active Member
- Joined
- Jan 8, 2008
- Messages
- 331
Hello EVERY ONE
I made this code that in the first time , identify a used range minus last row(there i have subtotals)
i Have 3 combobox to select columns.
I need a code to sort Ascending the selected range by selected columns
here what i've done till now.
I made this code that in the first time , identify a used range minus last row(there i have subtotals)
i Have 3 combobox to select columns.
I need a code to sort Ascending the selected range by selected columns
here what i've done till now.
Code:
Sub FindUsedRange_SORT()
Dim Rng1 As Range
CBO_Fill
Set Rng1 = RealUsedRange
If Rng1 Is Nothing Then
MsgBox "There is no used range, the worksheet is empty."
Else
Rng1.Select
End If
End Sub
Public Function RealUsedRange() As Range
Dim FirstRow As Long
Dim LastRow As Long
Dim FirstColumn As Integer
Dim LastColumn As Integer
On Error Resume Next
FirstRow = Cells.Find(What:="*", After:=Range("IV65536"), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
FirstColumn = Cells.Find(What:="*", After:=Range("IV65536"), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext).Column
LastRow = Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row - 1
LastColumn = Cells.Find(What:="*", After:=Range("A1"), LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
Set RealUsedRange = Range(Cells(FirstRow, FirstColumn), Cells(LastRow, LastColumn))
On Error GoTo 0
End Function
Private Sub CBO_Fill()
Dim oRng As Range
'Remplit la Combo
With ActiveSheet
Set oRng = Range(.Cells(1, 1), .Cells(1, Columns.Count).End(xlToLeft))
ComboBox1.List = Application.Transpose(oRng)
ComboBox2.List = Application.Transpose(oRng)
ComboBox3.List = Application.Transpose(oRng)
End With
ComboBox1.ListIndex = 0
ComboBox2.ListIndex = 0
ComboBox3.ListIndex = 0
End Sub