Locate a value in a cell and delete rows above

L

Louise

Hi,

I need a piece of code and I cannot work out how to write it in VBA. I want
the code to look for a static piece of code "Invoice Month" which will always
appear in column A, but could be in any row between 1-30. When it locates it,
I want it to delete all the rows above it but not the one it is on.

Is this possible and if so can anyone help me with the code I would need?

Many Thanks in advance for your help...
 
J

Jacob Skaria

Try the below macro

Sub Macro()
Dim lngRow As Long
lngRow = Range("A1:A30").Find(What:="Invoice Month", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
Rows("1:" & lngRow).Delete
End Sub

If this post helps click Yes
 
J

Jacob Skaria

It should be

Sub Macro()
Dim lngRow As Long
lngRow = Range("A1:A30").Find(What:="Invoice Month", _
SearchDirection:=xlPrevious, SearchOrder:=xlRows).Row
Rows("1:" & lngRow - 1).Delete
End Sub

If this post helps click Yes
 

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

Top