A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Well, the compile error message is gone but I still have my original problem where it sorts 3000 rows when I actually only have 1168 rows of data and puts the blanks at the top. The range that I want to sort has to be dynamic as the rows of data will only increase as this spreadsheet continues to get used. I was hoping to avoid the blank rows at the top after the sort by using LastRow. Is there an easier way to learn this stuff?
I think the problem is in the way you are calculating the last row. The UsedRange is property does not always return what you think it should. If there was data in a row below your final data that was deleted, Excel's UsedRange property can, under certain circumstances, keep remembering that cell as being the last data cell even though nothing is in it anymore. Also, if you format cells below your actual data, Excel's UsedRange will consider them as being used even if you don't put data in them yet. Try using this method of calculating the last row instead...
Dim LastRow As Long '<< Note I Dim'med this as Long, not Integer
LastRow = Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
Note the above will find the last displayed data value and it will ignore formulas displaying the empty string (""). If you need to locate the last row with either a value or formula (no matter what the formula is displaying, including the empty string) then use this instead...
Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlFormulas).Row
NOTE: Please mark the message or messages (yes, you can mark more than one) that answer your question as the "Answer" so that others will know your question has been resolved.