Select hundreds of rows by row number in Excel

I have a spreadsheet with about 11,000 rows. I have a list of about 700 row numbers that I want selected. They are somewhat random; not a specific 'range' of numbers.

Is there an easier way then scrolling through the spreadsheet and selecting these rows one by one?

The list of row numbers is in a .csv file, if that helps.

Thanks!

Possible solutions I'd like to implement: VB, C#, or something in Excel

Answers


What do you plan on doing with these rows? If you're looking for a VBA solution, I suggest taking this idea a step or two further. This is because it's not recommended to use .Select in code, but if it's simply that you're trying to get the row numbers and see the row, then it's fine...just a note.

This will take your row numbers, which I assume have been opened already and are in column A, from A1:A[whatever] without any breaks:

Sub test()
Dim lastRow As Integer, i As Integer, k As Integer
Dim rowNums() As Variant
Dim rng As Range, cel As Range

lastRow = Cells(1, 1).End(xlDown).Row
Set rng = Range(Cells(1, 1), Cells(lastRow, 1))

ReDim rowNums(1 To rng.Count)

rowNums = rng.Value

Dim addRows As Integer

For i = LBound(rowNums) To UBound(rowNums)
    If i >= rng.Count Then Exit For
    addRows = Range(Cells(rowNums(i, 1) + 1, 1), Cells(rowNums(i + 1, 1) - 1, 1)).Count
    'Range(Cells(rowNums(i, 1) + 1, 1), Cells(rowNums(i + 1, 1) - 1, 1)).Select
    Range(Cells(rowNums(i, 1) + 1, 1), Cells(rowNums(i + 1, 1) - 1, 1)).EntireRow.Delete
    For k = LBound(rowNums) To UBound(rowNums)
        rowNums(k, 1) = rowNums(k, 1) - addRows
    Next k
Next i

End Sub

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.