D
daniB
Hiya Everyone!
I maybe going about this in a very convoluted way.......
Im trying to highlight/select a variable range of cells....So far I
have this code which highlights one column depending on the length of
the column (data filled). but I need to select it in variable number
of rows
Sub SelectColumn()
Dim startCell As Range, cell1 As Range, cell2 As Range
Dim rowNr&, colNr&
Set startCell = ActiveCell
rowNr = startCell.Row: colNr = startCell.Column
If IsEmpty(startCell) Then Exit Sub
For rowNr = startCell.Column To 1 Step -1
If IsEmpty(Cells(rowNr, colNr).Value) Then
Set cell1 = Cells(rowNr + 1, colNr)
Exit For
End If
Next rowNr
If cell1 Is Nothing Then Set cell1 = Cells(1, colNr)
For rowNr = startCell.Row To 500
If IsEmpty(Cells(rowNr, colNr).Value) Then
Set cell2 = Cells(rowNr - 1, colNr)
Exit For
End If
Next rowNr
If cell2 Is Nothing Then Set cell2 = Cells(500, colNr)
Range(cell1, cell2).Select
End Sub
I think it is probably staring me in the face...or there is a really
quick way of doing this...Can anyone help??
Thanks!
I maybe going about this in a very convoluted way.......
Im trying to highlight/select a variable range of cells....So far I
have this code which highlights one column depending on the length of
the column (data filled). but I need to select it in variable number
of rows
Sub SelectColumn()
Dim startCell As Range, cell1 As Range, cell2 As Range
Dim rowNr&, colNr&
Set startCell = ActiveCell
rowNr = startCell.Row: colNr = startCell.Column
If IsEmpty(startCell) Then Exit Sub
For rowNr = startCell.Column To 1 Step -1
If IsEmpty(Cells(rowNr, colNr).Value) Then
Set cell1 = Cells(rowNr + 1, colNr)
Exit For
End If
Next rowNr
If cell1 Is Nothing Then Set cell1 = Cells(1, colNr)
For rowNr = startCell.Row To 500
If IsEmpty(Cells(rowNr, colNr).Value) Then
Set cell2 = Cells(rowNr - 1, colNr)
Exit For
End If
Next rowNr
If cell2 Is Nothing Then Set cell2 = Cells(500, colNr)
Range(cell1, cell2).Select
End Sub
I think it is probably staring me in the face...or there is a really
quick way of doing this...Can anyone help??
Thanks!