Result is not found from proper sorting

User avatar
PRADEEPB270
3StarLounger
Posts: 354
Joined: 27 Oct 2013, 15:11
Location: Gurgaon INDIA

Result is not found from proper sorting

Post by PRADEEPB270 »

This is my first macro written by me without any help taken from else.

Actually,I want to sort Column-I,If the figure is one ( 1) then sort according to ascending order of col.B.
And if the figure is 'zero' ( 0 or -) then sort according to ascending order of col.B.after sorting to above step i.e. digit '1'.

But the error are coming:-

Row No.1373 that should come row no.1386
Row No.1374 that should come at row no.1388
row no.1376 that should come at row no.7

Can anyone help me what are my mistakes that are providing result unwanted?

Please refre my attach file for more clarification.
Regards

Pradeep Kumar Gupta
INDIA

User avatar
HansV
Administrator
Posts: 78651
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Result is not found from proper sorting

Post by HansV »

You use End(xlDown) to determine the last row. But End(xlDown) stops when it encounters a blank cell/row. Since row 1372 is completely blank, only rows from 6 to 1371 are sorted, and all rows below that are ignored.
You could use the following instead:

Code: Select all

    Dim LastRow As Long
    LastRow = Range("B" & Rows.Count).End(xlUp).Row
LastRow will be 1387, the real last used row. The range to sort becomes Range("B6:Q" & LastRow)
Best wishes,
Hans

User avatar
PRADEEPB270
3StarLounger
Posts: 354
Joined: 27 Oct 2013, 15:11
Location: Gurgaon INDIA

Re: Result is not found from proper sorting

Post by PRADEEPB270 »

Thanks for suggestion.
Regards

Pradeep Kumar Gupta
INDIA