![]() |
Sort not working
Hi, I am having problems with my Code that sorts data based on differen criteria and then posts that data(based on the sort) to various sheet within the workbook. The code works great when there are three or mor rows of data, however, if I have less than 3 rows of data the cod either posts the data to the wrong sheet, double posts the data or doe not post the data at all. Is there a better way to sort the data? An example of my code is a follows: 'This part of the Macro formats the current data. Sheets("Download").Select Range("A1").Select Cells.Select Selection.Copy Sheets("Sorted").Select Cells.Select ActiveSheet.Paste Range("A1").Select Do While Len(Trim(Range("A1"))) = 0 Rows(1).Delete Loop Sheets("Download").Select Range("A1").Select Sheets("Sorted").Select Columns("C:D").Select Selection.Delete Shift:=xlToLeft Rows("1:1").Select Selection.Insert Shift:=xlDown Range("A1").Select ActiveCell.FormulaR1C1 = "Date" Range("B1").Select ActiveCell.FormulaR1C1 = "Amount" Range("C1").Select ActiveCell.FormulaR1C1 = "Description" Range("A1:C1").Select Selection.Font.Bold = True With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Columns("B:B").Select Selection.Style = "Comma" Columns("A:C").Select Selection.AutoFormat Format:=xlRangeAutoFormatSimple Number:=False, Font _ :=False, Alignment:=True, Border:=False, Pattern:=False Width:=True Range("A1").Select 'This part of the Macro sorts the data Range("D2").Select Application.CutCopyMode = False ActiveCell.FormulaR1C1 "=IF(OR(ISNUMBER(SEARCH({""fee"",""inter""},RC[-1]))),""F"",IF(OR(ISNUMBER(SEARCH({""transf"",""dire c pay"",""xf""},RC[-1]))),""T"",""O""))" Range("C2").Select Selection.End(xlDown).Offset(0, 1).Select ActiveCell.FormulaR1C1 = "end" Selection.End(xlUp).Select Selection.Copy Range("D3").Select Range(Selection, Selection.End(xlDown)).Select ActiveSheet.Paste Range("D2").Select Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.Copy Selection.PasteSpecial Paste:=xlValues Range("A1").Select Sheets("Sorted").Select Selection.AutoFilter Selection.AutoFilter Field:=4, Criteria1:="T" Range("A2:d2").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Sheets("transfers").Select Range("A2").Select ActiveSheet.Paste Columns("A:d").Select Columns("A:d").EntireColumn.AutoFit Sheets("Sorted").Select Application.CutCopyMode = False Selection.AutoFilter Field:=4, Criteria1:="O" Range("A2:d2").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Sheets("other").Select Range("A2").Select ActiveSheet.Paste Columns("A:d").Select Columns("A:d").EntireColumn.AutoFit Sheets("sorted").Select Application.CutCopyMode = False Selection.AutoFilter Field:=4, Criteria1:="F" Range("A2:d2").Select Range(Selection, Selection.End(xlDown)).Select Selection.Copy Sheets("Fees-Interest").Select Range("A2").Select ActiveSheet.Paste Columns("A:d").Select Columns("A:d").EntireColumn.AutoFit Sheets("sorted").Select Application.CutCopyMode = False Sheets("transfers").Select Range("A1").Select ActiveCell.FormulaR1C1 = "Date" Range("B1").Select ActiveCell.FormulaR1C1 = "Amount" Range("C1").Select ActiveCell.FormulaR1C1 = "Description" Range("A1:C1").Select Selection.Font.Bold = True With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Sheets("Fees-Interest").Select Range("A1").Select ActiveCell.FormulaR1C1 = "Date" Range("B1").Select ActiveCell.FormulaR1C1 = "Amount" Range("C1").Select ActiveCell.FormulaR1C1 = "Description" Range("A1:C1").Select Selection.Font.Bold = True With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Sheets("Other").Select Range("A1").Select ActiveCell.FormulaR1C1 = "Date" Range("B1").Select ActiveCell.FormulaR1C1 = "Amount" Range("C1").Select ActiveCell.FormulaR1C1 = "Description" Range("A1:C1").Select Selection.Font.Bold = True With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlBottom .WrapText = False .Orientation = 0 .AddIndent = False .IndentLevel = 0 .ShrinkToFit = False .ReadingOrder = xlContext .MergeCells = False End With Thanks -- STEVEB ------------------------------------------------------------------------ STEVEB's Profile: http://www.excelforum.com/member.php...fo&userid=1872 View this thread: http://www.excelforum.com/showthread...hreadid=509443 |
All times are GMT +1. The time now is 12:37 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com