Hi, My english is not good sorry :P
I have problem, I want sort data by 2nd line (rows )
example
1 surname#1
2 name#1
3 surname#2
4 name#2
5 surname#3
6 name#3
I want sorting only by surname, I dont know how
thank you for help
Hi, My english is not good sorry :P
I have problem, I want sort data by 2nd line (rows )
example
1 surname#1
2 name#1
3 surname#2
4 name#2
5 surname#3
6 name#3
I want sorting only by surname, I dont know how
thank you for help
Last edited by Marianus; 06-24-2013 at 09:18 AM.
heeeeeeeeeeelp![]()
Hi
See sample workbook. Formulas are in every other cell in column B. Then you can sort by surname.
Hope this helps.
Good luck.
Tony
I would suggest joining the surnames and first names together and then sorting and "unjoin" them afterwards. Something like:
(based on your data being in column A, starting at row 1)![]()
Sub macro_1() Dim count As Integer, max_count As Integer count = 1 Do Until Range("A" & count) = "" Range("A" & count) = Range("A" & count) & "," & Range("A" & count + 1) Range("A" & count + 1) = "" count = count + 2 Loop max_count = count Range("A1:A" & max_count).Sort Key1:=Range("A1"), Order1:=xlAscending count = 1 Do Until count >= max_count Rows(count + 1).Insert Range("A" & count + 1) = Right(Range("A" & count), Len(Range("A" & count)) - InStr(1, Range("A" & count), ",")) Range("A" & count) = Left(Range("A" & count), InStr(1, Range("A" & count), ",") - 1) count = count + 2 Loop End Sub
thank you but not work I want , as I thought
I need surname in 1st line a in 2nd name for tables
1 surname#1
2 name#1
3 surname#2
4 name#2
5 surname#3
6 name#3
- sort.xlsm
I know sort this :
1 surname#1 / name#1
2 surname#2 / name#2
3 surname#3 / name#3
... its easy
Last edited by Marianus; 06-24-2013 at 09:55 AM.
That's much more difficult. Especially as you are throwing in merged cells! You'll have to give me a minute to come up with a solution.
Ok, I've come up with this:
I've tested it against the sample you provided and it seems to work.![]()
Option Explicit Sub macro_1() Dim wS1 As Worksheet, wS2 As Worksheet, count As Integer, count_2 As Integer Set wS1 = ActiveSheet Set wS2 = Sheets.Add count = 3 count_2 = 3 Do Until wS1.Range("A" & count) = "" wS2.Range("A" & count_2) = wS1.Range("A" & count) wS2.Range("B" & count_2) = wS1.Range("A" & count + 1) wS2.Range("C" & count_2) = wS1.Range("B" & count) wS2.Range("D" & count_2) = wS1.Range("B" & count + 1) wS2.Range("E" & count_2) = wS1.Range("C" & count) wS2.Range("F" & count_2) = wS1.Range("D" & count) wS2.Range("G" & count_2) = wS1.Range("D" & count + 1) wS2.Range("H" & count_2) = wS1.Range("E" & count) count = count + 2 count_2 = count_2 + 1 Loop wS2.Range("A3:H" & count).Sort Key1:=Range("A3"), Order1:=xlAscending count = 3 For count_2 = 3 To count_2 wS1.Range("A" & count) = wS2.Range("A" & count_2) wS1.Range("A" & count + 1) = wS2.Range("B" & count_2) wS1.Range("B" & count) = wS2.Range("C" & count_2) wS1.Range("B" & count + 1) = wS2.Range("D" & count_2) wS1.Range("C" & count) = wS2.Range("E" & count_2) wS1.Range("D" & count) = wS2.Range("F" & count_2) wS1.Range("D" & count + 1) = wS2.Range("G" & count_2) wS1.Range("E" & count) = wS2.Range("H" & count_2) count = count + 2 Next Application.DisplayAlerts = False wS2.Delete Application.DisplayAlerts = True End Sub
thank you , but is error when is end I dont understand why
What is the error and where does it occur? I've just double-checked/tested it again and it still gave me the correct result for your sample.
Are you testing it on the sample or the full data?
look for this - sort.vA02.xlsm
The macro I gave you works on the data in sort.vA02.xlsm on my machine. Try putting it in a new module and running it from there rather than the command button? What is the error you get? Is it an error in the code? Or is the end result not what you want?
I work with command button , its my weakness, I use button to action and there si errror
Marianus, try changing this line in the code
![]()
wS2.Range("A3:H" & count).Sort Key1:=wS2.Range("A3"), Order1:=xlAscending
Thank you for all
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks