Search from bottom of column up column and delete to top

  • Thread starter Thread starter Jools
  • Start date Start date
J

Jools

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!
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top