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:
Private Sub CommandButton2_Click()
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.Add Key:=ActiveCell. _
Offset(0, 2).Range("A1:A9992"), SortOn:=xlSortOnValues, Order:=xlAscending, _
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin