Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 41
Default Search a sheet for a date then delete the row, repeat until the lastrow of the table.

Hi,hope I can explain this right, if someone is able to help please.

I have a table of data, column B has some text in it, column H has
dates.

I want to go down the table for each row, to the last row (which may
vary in address) and check if a date in each row is over a month from
todays date, and if so delete the that row then move to the next.

I have a <TAGR field which will always be after the last row if
genuine data, so I figured if I find this I could set the lastrow
number, but not sure how as I can only return the address. Can I use
Left or something on this value to get the number?

Cells.Find(What:="<TAGR", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
lastrow = ActiveCell.Address(False, False)

So one I have worked out how to do this I figure if I go down column B
to check it isn't <TAGR and if it isnt use ActiveCell.Offset to then
go to column H for that row and check the date. Again not sure how to
do this, I have attempted the logic, but as previously posted I don't
know about coding!

Range("B6").Select

mynow = Now()
mydate = Format(mynow, "dd/mm/yyyy")

For A = 1 To lastrow
If ActiveCell.Value = "<TAGR" Then
Set A = lastrow
Next A
Else
ActiveCell.Offset(0, 6).Activate
'what do i put here?
Else: Selection.EntireRow.Delete
Next A

Cheers

Rich
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 47
Default Search a sheet for a date then delete the row, repeat until the la

Hello.

this should do what you are after.

Sub DateChecker()

Dim Lineindex As Integer
'Start at Row 2 - allowing for headings
Lineindex = 2
'Keep going until <TARG
Do Until Range("B" & Lineindex) = "<TARG"
'Date over 31 days old
If Range("H" & Lineindex) < Date - 31 Then
Range("A" & Lineindex).Select
ActiveCell.EntireRow.Delete
Else
Lineindex = Lineindex + 1
End If
Loop
Range("A1").Select

End Sub
--
Kevin Smith :o)


"Richhall" wrote:

Hi,hope I can explain this right, if someone is able to help please.

I have a table of data, column B has some text in it, column H has
dates.

I want to go down the table for each row, to the last row (which may
vary in address) and check if a date in each row is over a month from
todays date, and if so delete the that row then move to the next.

I have a <TAGR field which will always be after the last row if
genuine data, so I figured if I find this I could set the lastrow
number, but not sure how as I can only return the address. Can I use
Left or something on this value to get the number?

Cells.Find(What:="<TAGR", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
lastrow = ActiveCell.Address(False, False)

So one I have worked out how to do this I figure if I go down column B
to check it isn't <TAGR and if it isnt use ActiveCell.Offset to then
go to column H for that row and check the date. Again not sure how to
do this, I have attempted the logic, but as previously posted I don't
know about coding!

Range("B6").Select

mynow = Now()
mydate = Format(mynow, "dd/mm/yyyy")

For A = 1 To lastrow
If ActiveCell.Value = "<TAGR" Then
Set A = lastrow
Next A
Else
ActiveCell.Offset(0, 6).Activate
'what do i put here?
Else: Selection.EntireRow.Delete
Next A

Cheers

Rich

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,722
Default Search a sheet for a date then delete the row, repeat until the la

'In order to prevent confusion by deleting a row and then going down,
'because that would move an unsearched row into a spot we had
'just searched, it's better to start at the bottom. This macro should do
'what you're are trying to accomplish.

Sub FindAndDelete()

Application.ScreenUpdating = False

'Assuming you meant look for dates older than 1 month
x = DateSerial(Year(Date), Month(Date) - 1, Day(Date))

'Find the <TAGR value
For Each Cell In Range("B:B")
If Cell.Value = "<TAGR" Then
'Search until row right before <TAGR
lastrow = Cell.Row - 1
Exit For
End If
Next Cell

'Start at bottom, work our way up
For A = lastrow To 1 Step -1
With Cells(A, "H")
If .Value <= x Then
.EntireRow.Delete
End If
End With
Next A

Application.ScreenUpdating = True

End Sub
--
Best Regards,

Luke M
*Remember to click "yes" if this post helped you!*


"Richhall" wrote:

Hi,hope I can explain this right, if someone is able to help please.

I have a table of data, column B has some text in it, column H has
dates.

I want to go down the table for each row, to the last row (which may
vary in address) and check if a date in each row is over a month from
todays date, and if so delete the that row then move to the next.

I have a <TAGR field which will always be after the last row if
genuine data, so I figured if I find this I could set the lastrow
number, but not sure how as I can only return the address. Can I use
Left or something on this value to get the number?

Cells.Find(What:="<TAGR", After:=ActiveCell, LookIn:=xlFormulas,
LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
lastrow = ActiveCell.Address(False, False)

So one I have worked out how to do this I figure if I go down column B
to check it isn't <TAGR and if it isnt use ActiveCell.Offset to then
go to column H for that row and check the date. Again not sure how to
do this, I have attempted the logic, but as previously posted I don't
know about coding!

Range("B6").Select

mynow = Now()
mydate = Format(mynow, "dd/mm/yyyy")

For A = 1 To lastrow
If ActiveCell.Value = "<TAGR" Then
Set A = lastrow
Next A
Else
ActiveCell.Offset(0, 6).Activate
'what do i put here?
Else: Selection.EntireRow.Delete
Next A

Cheers

Rich

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 41
Default Search a sheet for a date then delete the row, repeat until thela

Thank you thats brilliant,cheers.
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
Repeat keystrokes to delete character in column Graeme at Raptup Excel Worksheet Functions 5 October 4th 07 05:57 PM
Search for repeat words in Excel database Jackpine Excel Discussion (Misc queries) 5 January 9th 07 11:31 PM
need macro script - repeat to delete 2 rows BB Excel Discussion (Misc queries) 3 November 14th 06 12:00 AM
Match, Copy, Merge, Delete and Repeat... MVP's this one's for you. dannyfromnj Excel Discussion (Misc queries) 1 June 19th 06 10:14 PM
Quick Macro question - How to delete two rows then skip one - and repeat David Smithz Excel Discussion (Misc queries) 3 March 3rd 06 02:58 PM


All times are GMT +1. The time now is 04:24 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"