• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need Help on below dynamic row sorting macro :-

Manan

New Member
I am doing the sorting on dynamic number of rows as my input comes from web application that sometimes have 1000 rows and sometime 500 or 200 etc.. I wrote the below macro but I am getting error Application error or Object defined error on
lng = Range("G" & .Rows.Count).End(x1Up).Row.

Code:
Sub Sort()
' Sort Macro
'
  Dim lng As Long
 
  lng = Range("G" & .Rows.Count).End(x1Up).Row
 
  ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
  ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("G9:G" & lng _
  ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
  With ActiveWorkbook.Worksheets("Sheet1").Sort
  .SetRange Range("G8:N" & lng)
  .Header = xlYes
  .MatchCase = False
  .Orientation = xlTopToBottom
  .SortMethod = xlPinYin
  .Apply
  End With
End Sub

please suggest solution.
 
Last edited by a moderator:
Hi ,

Change the offending line to :

lng = Range("G" & .Rows.Count).End(xlUp).Row

where the highlighted character is the letter L , not the digit 1.

Narayan
 
Back
Top