ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selection Question (https://www.excelbanter.com/excel-programming/376646-selection-question.html)

bodhisatvaofboogie

Selection Question
 
lastrow = Cells(Rows.Count, "K").End(xlUp).Row
Cells.Find(What:="WH", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=True) _
.EntireRow.Select

This formula works to find the cell in Range("A:A") with "WH" in it then
select the entire row. What I WANT to do next is select every row above that
selection, not including the selection and delete them.

Example:
That row ends up being row 30, so what I want is row 29 all the way up to 1
all to be selected and deleted. Any ideas??? THANKS!!!

Tom Ogilvy

Selection Question
 
Dim rng as Range, lastrow as Long
lastrow = Cells(Rows.Count, "K").End(xlUp).Row
set rng = Range("A:A").Find(What:="WH", _
After:=Range("A65536"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext,
MatchCase:=True)
If not rng is nothing then
Range(Range("A1"),rng.offset(-1,0)).EntireRow.Delete
End if

--
Regards,
Tom Ogilvy

"bodhisatvaofboogie" wrote:

lastrow = Cells(Rows.Count, "K").End(xlUp).Row
Cells.Find(What:="WH", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=True) _
.EntireRow.Select

This formula works to find the cell in Range("A:A") with "WH" in it then
select the entire row. What I WANT to do next is select every row above that
selection, not including the selection and delete them.

Example:
That row ends up being row 30, so what I want is row 29 all the way up to 1
all to be selected and deleted. Any ideas??? THANKS!!!


Susan

Selection Question
 
after .entirerow.select
then you need to move the cell one row above, select all the rows
above, & delete them.

ActiveCell.Offset(-1, 0).Select

Range(Selection, Selection.End(xlUp).End(xlToRight)).Delete
xxxxxxxxxxxxxxxxx
susan

bodhisatvaofboogie wrote:
lastrow = Cells(Rows.Count, "K").End(xlUp).Row
Cells.Find(What:="WH", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=True) _
.EntireRow.Select

This formula works to find the cell in Range("A:A") with "WH" in it then
select the entire row. What I WANT to do next is select every row above that
selection, not including the selection and delete them.

Example:
That row ends up being row 30, so what I want is row 29 all the way up to 1
all to be selected and deleted. Any ideas??? THANKS!!!




All times are GMT +1. The time now is 04:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com