ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Search from bottom of column up column and delete to top (https://www.excelbanter.com/excel-programming/404779-search-bottom-column-up-column-delete-top.html)

jools

Search from bottom of column up column and delete to top
 
New to Excel VBA, trying to find out:

1. How to search (or find) from the bottom of a column upwards.

2. Once the search result is found I need to delete all the column data from
that result up to row 2 of the column.

Can anyone help? I've been messing around with this for a few weeks now and
cannot figure it out - sorry!

Dave Peterson

Search from bottom of column up column and delete to top
 
Start at the top of the column and look for the previous value.

dim FoundCell as range
with worksheets("somesheet")
with .range("e:e") 'for example
Set foundcell = .Cells.Find(What:="whatareyoulookingfor", _
After:=.Cells(1), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False)
end with

if foundcell is nothing then
'not found, what should happen
else
if foundcell.row < 2 then
msgbox "not found below 1--what should happen here"
else
.rows(2 & ":" & foundcell.row).delete
end if
end if
end with

Jools wrote:

New to Excel VBA, trying to find out:

1. How to search (or find) from the bottom of a column upwards.

2. Once the search result is found I need to delete all the column data from
that result up to row 2 of the column.

Can anyone help? I've been messing around with this for a few weeks now and
cannot figure it out - sorry!


--

Dave Peterson


All times are GMT +1. The time now is 12:50 PM.

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