R RocketRod Oct 6, 2008 #1 Can someone show me the code to select the current row and the 2 above it?
F FSt1 Oct 6, 2008 #2 hi try this... Range(ActiveCell.EntireRow, ActiveCell.Offset(-2, 0)).Select regards FSt1
R Ron Rosenfeld Oct 6, 2008 #3 Can someone show me the code to select the current row and the 2 above it? Click to expand... =========================================== Dim rg As Range Dim lNumRows As Long lNumRows = Application.WorksheetFunction.Min _ (3, ActiveCell.Row) Set rg = ActiveCell.Offset(-lNumRows + 1, 0).EntireRow Set rg = rg.Resize(rowsize:=lNumRows) rg.Select ================================================= --ron
Can someone show me the code to select the current row and the 2 above it? Click to expand... =========================================== Dim rg As Range Dim lNumRows As Long lNumRows = Application.WorksheetFunction.Min _ (3, ActiveCell.Row) Set rg = ActiveCell.Offset(-lNumRows + 1, 0).EntireRow Set rg = rg.Resize(rowsize:=lNumRows) rg.Select ================================================= --ron
R Rick Rothstein Oct 6, 2008 #5 Here's one more for you to consider... Rows((ActiveCell.Row - 2) & ":" & ActiveCell.Row).Select Although you might want to put in a check to make sure the active cell is at Row 3 or greater... If ActiveCell.Row > 2 Then Rows((ActiveCell.Row - 2) & _ ":" & ActiveCell.Row).Select And, if you use a With block whose reference is the ActiveCell then either this... With ActiveCell ..... Rows((.Row - 2) & ":" & .Row).Select ..... End With or this... With ActiveCell ..... If .Row > 2 Then Rows((.Row - 2) & ":" & .Row).Select ..... End With depending on if you need to check the active cell's row number for being greater than 2 or not.
Here's one more for you to consider... Rows((ActiveCell.Row - 2) & ":" & ActiveCell.Row).Select Although you might want to put in a check to make sure the active cell is at Row 3 or greater... If ActiveCell.Row > 2 Then Rows((ActiveCell.Row - 2) & _ ":" & ActiveCell.Row).Select And, if you use a With block whose reference is the ActiveCell then either this... With ActiveCell ..... Rows((.Row - 2) & ":" & .Row).Select ..... End With or this... With ActiveCell ..... If .Row > 2 Then Rows((.Row - 2) & ":" & .Row).Select ..... End With depending on if you need to check the active cell's row number for being greater than 2 or not.