PDA

View Full Version : Solved: Find last row



Codeblue
07-05-2012, 06:59 AM
I use this for sorting and wanted to go to the last row

If Columns("C:C").Select Then
Range("C2").Select
ActiveWorkbook.Worksheets("sensitive_data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("sensitive__3I10Y35OM_data").Sort.SortFields.Add Key _
:=Range("C2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("sensitive__3I10Y35OM_data").Sort
'.SetRange Range("A2:G1500") ' this worked but limited the range
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
'.Apply ' this caused error when I added the next line of code
End With
Range("A65536").End(xlUp).EntireRow.Delete Shift:=xlUp
End If

Bob Phillips
07-05-2012, 07:50 AM
If Columns("C:C").Select Then
Range("C2").Select
ActiveWorkbook.Worksheets("sensitive_data").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("sensitive__3I10Y35OM_data").Sort.SortFields.Add Key _
:=Range("C2"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("sensitive__3I10Y35OM_data")

.Sort.SetRange .Range(.Range("A2"), .Range("A2").End(xlDown).Resize(, 7))
With .Sort

.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With

Range("A65536").End(xlUp).EntireRow.Delete Shift:=xlUp
End If

Codeblue
07-05-2012, 08:03 AM
thanks for the reply
I'm getting an error "Object doesn't support this method or property"

.Sort.SetRange .Range(.Range("A2"), .Range("A2").End(xlDown).Resize(, 7))

on this line.

Bob Phillips
07-05-2012, 12:22 PM
Maybe wrongly placed bracket

.Sort.SetRange .Range(.Range("A2"), .Range("A2").End(xlDown)).Resize(, 7)

Codeblue
07-06-2012, 05:48 AM
thanks, yes that fixed it.