LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Find and delete offset loop

Traditional.. yes, but also the least efficient.

--
Rick (MVP - Excel)


"john" wrote in message
...
The most traditional approach to tackle this task is to loop through the
entire column, check to see if each cell contains the value and, if it
does,
delete the row. Since Excel shifts rows upwards when they are deleted, it
is
best to start at the bottom of the column and work upwards thereby
negating
the row shift effect.

I am not sure that I have fully understood your request but have a play
with
the following code & see if it gets you started.

Sub DeleteRows()
Dim EndRow As Long
Dim StartRow As Long
Dim Lr As Long

'ignore header
StartRow = 2

With Worksheets("Sheet1")

EndRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For Lr = EndRow To StartRow Step -1

If .Cells(Lr, 1).Value = "Chargeable Hours" Then

If Not IsEmpty(.Cells(Lr, 1).Offset(1, 1).Value) Then

.Rows(Lr).EntireRow.Delete

End If

End If

Next

End With
End Sub

--
jb


"Karin" wrote:

I've got this far, but I don't know how to tell it to stop when it can't
find
it anymore.

Do
Cells.Find(What:="Chargeable Hours", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows,
SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate

ActiveCell.Offset(1, 1).Select

If Not IsEmpty(ActiveCell.Value) Then
ActiveCell.Rows("1:1").EntireRow.Select
Selection.Delete Shift:=xlUp
End If


"Karin" wrote:

Hi,
I want to find "chargeable hours", then go down 1 row and see if there
is
any data in column B -- if there IS data, I want to delete the row. I
want
to loop through the spreadsheet.
Thank you!


 
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
Smaller VBA? Loop or Offset? Qaspec Excel Programming 3 September 23rd 09 01:00 PM
Offset in for loop not working StumpedAgain Excel Programming 4 June 2nd 08 07:41 PM
Find, Copy offset to offset on other sheet, Run-time 1004. Finny[_3_] Excel Programming 10 December 7th 06 11:46 PM
find, delete, repeat loop [email protected] Excel Programming 2 July 18th 06 07:21 PM
Loop with activecell.offset mthomas[_17_] Excel Programming 3 November 18th 05 09:29 PM


All times are GMT +1. The time now is 03:26 AM.

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

About Us

"It's about Microsoft Excel"