How do I get an Excel range using row and column numbers in VSTO / C#?

后端 未结 9 1951
萌比男神i
萌比男神i 2020-12-05 13:07

I think the question sums it up. Given two integers for row and column or four integers for row and column for the two corners of a range, how do I get a range object for th

9条回答
  •  一个人的身影
    2020-12-05 13:41

    Facing the same problem I found the quickest solution was to actually scan the rows of the cells I wished to sort, determine the last row with a non-blank element and then select and sort on that grouping.

        Dim lastrow As Integer
    lastrow = 0
    For r = 3 To 120
       If Cells(r, 2) = "" Then
            Dim rng As Range
            Set rng = Range(Cells(3, 2), Cells(r - 1, 2 + 6))
            rng.Select
            rng.Sort Key1:=Range("h3"), order1:=xlDescending, Header:=xlGuess, DataOption1:=xlSortNormal
            r = 205
        End If
    Next r
    

提交回复
热议问题