Sorting a Non-contiguous range
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I'm wondering how I possibly write iLogic code to sort a non-contiguous range in Excel.
Before my companies most recent revision to this code, we had 2 ranges in our Excel output that were sorted separately based on their own first columns. Because of other changes, I now have 3 separate ranges, say 1, 2, & 3, separated by empty columns. With 1 & 3 being an old continuous range. Yet, 1 & 3 need to be sorted TOGETHER as one range based on the first column of range 1.
The code I'm trying to use is:
'Declare ranges
oRng1 = .Workbooks(wb).Sheets(ws).Range("A" & subTitleRow + 1 & ":" & "G" & lastRow1 & "," & "N" & subTitleRow + 1 & ":" & "O" & lastRow1) oRng2 = .Workbooks(wb).Sheets(ws).Range("I" & subTitleRow+1 & ":" & "L" & lastRow2) 'Sort ranges by Part Number
oRng1.Sort(key1 :=.Range("A" & subTitleRow + 1 & ":" & "G" & lastRow1 & "," & "N" & subTitleRow + 1 & ":" & "O" & lastRow1), Header :=xlNo) oRng2.Sort(key1:=.Range("I" & subTitleRow+1 & ":" & "L" & lastRow2), Header:=xlNo)
I end up getting this error:
Note: line 625 is the oRng1.Sort line.
I only included these 4 lines of a 1200 line code that is otherwise working perfectly. As a matter of fact, if I change the first line to oRng1 = .Workbooks(wb).Sheets(ws).Range("A" & subTitleRow + 1 & ":" & "G" & lastRow1) everything works fine, EXCEPT columns N & O are not sorted.
Any help would be appreciated.
TlDR: How do you sort a non-contiguous range in Excel using iLogic?