selecting a row in vba problem
i am programmatically selecting a row in VBA but it is giving me a TYPE MISMATCH error on this:
Rows(Str(i) & ":" & Str开发者_Python百科(i)).Select
what am i doing wrong?
For i = 5 To 1000
If Worksheets("5470").Cells(i, 2) = "" Then
Rows(Str(i) & ":" & Str(i)).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Selection.Delete Shift:=xlUp
Exit For
End If
Next i
Why not use
Rows(i).Select
Afaik, rows can be indexed by the row number too.
Alternative:
Cells(i, 1).EntireRow.Select
The error you are getting is because the STR functions prepends a space to the number. So, when i=100, you'll get " 100: 100". You could the method of GolezTrol, or use cstr() instead of str(). The space is prepended to account for a possible negative value.
精彩评论