Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete Specific Rows Using VBA


I am working on a worksheet with dates in column G starting in G2 the
last under the last row containign a date has " " in it.

The dates are formatted dd/mm/yyyy.

I need an input box which prompts me for a date and then formats the
reply in the same way dd/mm/yyyy.

I then want the macro to run down row G until it reaches the " " and
delete any row with a date before the date enterred into the input box.

All and any help much appreciated.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=76632

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 56
Default Delete Specific Rows Using VBA

If the regional settings of your computer are set for dd/mm/yyyy
format, then Excel should be able to convert the string returned by
the inputbox correctly. Try this, but you should clean up the
"activesheet" references so that users cannot change the active sheet
mid-process and end up with an unexpected result.

Public Sub DeleteRows()
Dim sDate As String, lRow As Long, lCount As Long
sDate = InputBox("Please enter the date")
If IsDate(sDate) Then
lRow = 2
For lCount = 2 To ActiveSheet.UsedRange.Rows.Count
If ActiveSheet.Cells(lRow, 7).Value < DateValue(sDate)
Then
ActiveSheet.Cells(lRow, 7).EntireRow.Delete
Else
lRow = lRow + 1
End If
Next lCount
Else
MsgBox sDate & " does not appear to be a valid date"
End If
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Delete Specific Rows Using VBA

If there are no dates below your " ", then then this should work. You
will need to change resp to whatever variable you are using on the input
box.

Sub something()
lr = ActiveSheet.Cells(Rows.Count, 7).End(xlUp).Row
Set rng = ActiveSheet.Range("G2:G" & lr)
resp = InputBox("enter date", "Date")
dt = Format(resp, "dd/mm/yyyy")
For i = lr To 2 Step - 1
If ActiveSheet.Cells(i, 7) < dt Then
ActiveSheet.Cells(i, 7).EntireRow.Delete
End If
Next
End Sub


"Timbo" wrote in message
...

I am working on a worksheet with dates in column G starting in G2 the
last under the last row containign a date has " " in it.

The dates are formatted dd/mm/yyyy.

I need an input box which prompts me for a date and then formats the
reply in the same way dd/mm/yyyy.

I then want the macro to run down row G until it reaches the " " and
delete any row with a date before the date enterred into the input box.

All and any help much appreciated.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=76632



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Delete Specific Rows Using VBA

You might need to change this line.

dt = Format(resp, "dd/mm/yyyy")

To:

dt = CDate(Format(resp, "dd/mm/yyyy"))

if column G is formatted as Date.


"Timbo" wrote in message
...

I am working on a worksheet with dates in column G starting in G2 the
last under the last row containign a date has " " in it.

The dates are formatted dd/mm/yyyy.

I need an input box which prompts me for a date and then formats the
reply in the same way dd/mm/yyyy.

I then want the macro to run down row G until it reaches the " " and
delete any row with a date before the date enterred into the input box.

All and any help much appreciated.


--
Timbo
------------------------------------------------------------------------
Timbo's Profile: http://www.thecodecage.com/forumz/member.php?userid=24
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=76632



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
Delete rows with specific text David New Users to Excel 5 April 3rd 23 07:29 PM
Delete Rows Without Specific Text waggett Excel Worksheet Functions 6 October 6th 09 11:34 AM
Macro to delete specific rows Gert-Jan[_2_] Excel Programming 2 December 20th 06 09:29 AM
Delete rows with specific text MAYDAY[_3_] Excel Programming 8 June 7th 05 08:38 PM
Macro to delete specific rows Steve Excel Programming 12 October 1st 04 11:50 PM


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

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"