Theres a range of cells from A:9 to D:9 and down until it have data.
I must copy paste those cells with the data to the worksheet 2, and I have to sort them by their year in ascending order!
Thing is, I made the code with recording a macro, but if I put it under the command button section it doesn't work!
Unfortunately if I debug that command button code, and run it step by step the code works like a charm!!
What am I doing wrong?
Here's the code:
Code:Private Sub CommandButton2_Click() Worksheets("Munka1").Range("A9:D10000").Cells.Copy Worksheets("Munka2").Range("A1:D10000").PasteSpecial 'I copy paste a lot of spaces because I don't know how to set it to only copy those cells wheres data! 'This would be the macro I've recorded this part should work fine at least it does when in debug mode... Application.CutCopyMode = False ActiveWorkbook.Worksheets("Munka2").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Munka2").Sort.SortFields.Add Key:=ActiveCell. _ Offset(0, 2).Range("A1:A9992"), SortOn:=xlSortOnValues, Order:=xlAscending, _ DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Munka2").Sort .SetRange ActiveCell.Range("A1:D9992") .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Sub


Reply With Quote
10000").Cells.Copy