how to select multiple rows using vba

  • Thread starter Thread starter almostthere
  • Start date Start date
A

almostthere

I want to select multiple rows (so I can then sort them)

This is what I have so far:

Do While Worksheets(I).Cells(InputRow, 1).Value <> ""
Rows(InputRow).Select
InputRow = InputRow + 1
Loop

But it just highlights the specific row everytime it goes through th
loop and the one that was highlighted is not anymore.

I want to have the rows STAY highlighted after it goes through th
loop.

Thanks:
 
Are you SURE you want to select all those rows? I ask because, wit
VERY few exceptions, it is just as effective and MUCH faster to do th
same job without selecting anything at all. If you post a little mor
detail about what you're trying to accomplish maybe we could make som
suggestions about how you're going about it. - Piku
 
Try something like

Do While Worksheets(I).Cells(InputRow, 1).Value <> ""
Range(Cells(1, 1), Cells(InputRow, 1)).EntireRow.Select
InputRow = InputRow + 1
Loop


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Well I am trying to find a way to sort a certain number of cells
alphabetically. Selecting the rows, then sorting them is the only wa
I could think of doing it.

For example say i have this

Row 34: Burkom, Diane
Row 35: Hartford, Pamela
Row 36: Adrian, Steve
Row 37: (Blank)

InputRow currently has the value 34, and so I want to be able to onl
sort rows 34 through 36.

Make better sense? Please let me know. Thanks

Cheer
 
Oh and there are various columns to each row, containing number of hour
worked for each across the number of months
 
Chip said:
Try something like

Do While Worksheets(I).Cells(InputRow, 1).Value <> ""
Range(Cells(1, 1), Cells(InputRow, 1)).EntireRow.Select
InputRow = InputRow + 1
Loop


Worked Great!!!:cool: Thanks:
 
I had a little trouble with that code because it would highlight all o
the rows above InputRow. So what I did was create another variabl
("InputRow2") and did not change that variable in the loop. Jus
posting this in case someone else is has same question.

Dim InputRow As Integer
Dim InputRow2 As Integer
InputRow = 55
InputRow2 = InputRow

Do While Worksheets("Summary").Cells(InputRow, 1).Value <> ""
Range(Cells(InputRow2, 1), Cells(InputRow, 1)).EntireRow.Select
InputRow = InputRow + 1
Loop
End Su
 
Back
Top