Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 217
Default Locate a value in a cell and delete rows above

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...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Locate a value in a cell and delete rows above

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
---------------
Jacob Skaria


"Louise" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Locate a value in a cell and delete rows above

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
---------------
Jacob Skaria


"Louise" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 217
Default Locate a value in a cell and delete rows above

Hi Jacob,

This works a treat! :) Thank you SO much!

Kind regards,
Louise

"Jacob Skaria" wrote:

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
---------------
Jacob Skaria


"Louise" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locate duplicates in column A, then, delete the row Gary Excel Worksheet Functions 3 June 19th 08 01:54 AM
locate positive numbers and delete rows containing Giggly4g Excel Discussion (Misc queries) 3 April 2nd 08 03:47 AM
Delete Rows if any cell in Column H is blank but do not Delete Fir manfareed Excel Programming 4 September 28th 07 05:20 PM
How can I delete links (I can't locate) from one file to another? Vin C. Excel Discussion (Misc queries) 1 April 25th 06 09:30 PM
Locate and delete specific cells David Smith Excel Discussion (Misc queries) 1 January 19th 05 04:45 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"