0

I got an error as Sort method out of range. At the beginning I got the same error, and after the enhancement of my code I haven't seen this error any more.

Now again it's showing the same error when I execute. Is the not the effective way of coding ?

With Master_workbook.Worksheets("warehouse")

         'Last row and last column in worksheet("warehouse")

            Ws1_Lrow = .Cells.Find("*", .Range("A1"), xlFormulas, , xlByRows, xlPrevious).Row
            Ws1_Lcol = .Cells.Find("*", .Range("A1"), xlFormulas, , xlByColumns, xlPrevious).Column
            Set rngFilter = .Range(.Cells(1, 1), .Cells(Ws1_Lrow, Ws1_Lcol))

                Selection.Sort Key1:=Range("W2"), Order1:=xlDescending, Header:=xlGuess, OrderCustom:=1, Orientation:=xlTopToBottom

            Master_workbook.Worksheets("warehouse").Columns("Z:Z").Cut
            Master_workbook.Worksheets("warehouse").Columns("U:U").Insert Shift:=xlToRight 
end with
Community
  • 1
  • 1

1 Answers1

0
  1. Change Selection to rngFilter
  2. Change Key1:=Range("W2") to Key1:=.Range("W2") Notice the dot before the range?
  3. If there is no data in the worksheet then the way you are trying to find the row and col will give you an error. You may want to see This
  4. Ensure that Range("W2") is in rngFilter range. You can use Intersect to check for it
Community
  • 1
  • 1
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250