• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How Do I Select The Active Cell Row (But Not The Entire Row)?

Simple Question...


I'm simply looking to select from a START POINT in the row to an END POINT in the active row (i.e. whichever row the active cell happens to be in of course).


A straight line selection on the active cell row is all I'm needing help with, but the tricky part I'm running into is that-


For instance... if my active cell happened to be in A1...


Range("A1:G1").Select


However, the only catch is that there could be random data scattered in any one cell in this snippet of row (so a contiguous code will not work).


Also, I never know which row I'll actually be on (hence A1:G1 was just an example).


I've always struggled with these types of selections, so any help is extreeemly appreciated.
 
Do you mean you want to select all cells with data in it?


[pre]<br />
Dim rng As Range</p>
<p> Set rng = ActiveCell.EntireRow.SpecialCells(xlCellTypeConstants)<br />
MsgBox rng.Address<br />
[/pre]
 
Have a look at this code

[pre]
Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Excel.Range)
Dim maxcol As Long

If Target.Value = "" Then Exit Sub
If Application.Version > 12 Then
maxcol = 16384
Else
maxcol = 256
End If

Application.EnableEvents = False
If Cells(Target.Row, 1) <> "" Then
Range(Cells(Target.Row, 1), Cells(Target.Row, maxcol).End(xlToLeft)).Select
Else
Range(Cells(Target.Row, 1).End(xlToRight), Cells(Target.Row, maxcol).End(xlToLeft)).Select
End If

Application.EnableEvents = True
End Sub
[/pre]
 
Back
Top