Hello.
I have a list of products that I want to sort by clicking on a button.
I attached a sample book and here is the code with commentary.
Sub AZ()
Dim Search_Cell As Range
Dim Sort_Range As Range
Dim FirstRow As Range
Dim LastRow As Range
Set Search_Cell = Sheets("Sheet1").Range("A:AAA").Find("Supprechner", , xlValues, xlPart, xlByRows, xlNext, False, False, False)
Set FirstRow = Search_Cell.Offset(3, 0)
'FirstRow is the first row with a number
Set LastRow = Range(FirstRow, Search_Cell.Offset(200, 0).Find("", , xlFormulas, xlPart, xlByRows, xlNext, False, False, False)).Offset(-1)
'LastRow should be the last number in this column
Set Sort_Range = Range(FirstRow.Offset(0, 1), LastRow.Offset(0, 1))
'SortRange includes the cells that are to be sorted alphabetically
Sort_Range.Sort Key1 = .Search_Cell.Offset(3, 1), Order1 = xlSort, Header = xlNo, OrderCustom = 1, MatchCase = False, Orientation = xlTopToBottom, DataOption1 = xlSortNormal
'Now I tried to sort it, Key1 shall be "Arginin HCl
End Sub
Thanks a lot in advance!
Bookmarks