PC Review


Reply
Thread Tools Rate Thread

Delete rows based on date input

 
 
bingshuo.li@gmail.com
Guest
Posts: n/a
 
      17th Nov 2008
Hi,

I am very new to VBA programming and I need help.

I am thinking to write a macro which can -
1. Pop out a window to ask the user to input the beginning date in MM/
DD/YY format.
2. Pop out another window to ask the user to input the ending date in
MM/DD/YY format.
3. Then the macro deletes rows based on the entered date period (all
rows between the beginning date and the ending date will be deleted).

In the target excel worksheet, dates are recorded in column B.

Can anyone help? Thanks!!!!!

 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      17th Nov 2008
You can use EasyFilter if you want to do this
http://www.rondebruin.nl/easyfilter.htm


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


<(E-Mail Removed)> wrote in message news:e6ca0fb1-8fb5-4c0e-8061-(E-Mail Removed)...
> Hi,
>
> I am very new to VBA programming and I need help.
>
> I am thinking to write a macro which can -
> 1. Pop out a window to ask the user to input the beginning date in MM/
> DD/YY format.
> 2. Pop out another window to ask the user to input the ending date in
> MM/DD/YY format.
> 3. Then the macro deletes rows based on the entered date period (all
> rows between the beginning date and the ending date will be deleted).
>
> In the target excel worksheet, dates are recorded in column B.
>
> Can anyone help? Thanks!!!!!
>

 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      17th Nov 2008
Sub deleterows()
On Error GoTo ErrHandler
Dim startDate As Date
Dim endDate As Date
Dim rng As Range
Dim i As Long

startDate = InputBox("Enter Start Date as mm/dd/yy format")
endDate = InputBox("Enter EndDate as mm/dd/yy format")

Set rng = ActiveSheet.Range(Cells(1, "B"), Cells(Rows.Count, "B").End(xlUp))

'Work backwards from bottom to top when deleting rows
With rng
For i = .Rows.Count To 1 Step -1
If .Cells(i).Value > startDate And .Cells(i).Value < endDate Then
.Cells(i).EntireRow.delete
End If
Next i
End With
Exit Sub
ErrHandler:
Select Case Err.Number
Case Is = 13
MsgBox "Date is not in proper format"
Case Else
MsgBox "Error #" & Err.Number & vbCrLf & Err.Description
End Select
End Sub

"(E-Mail Removed)" wrote:

> Hi,
>
> I am very new to VBA programming and I need help.
>
> I am thinking to write a macro which can -
> 1. Pop out a window to ask the user to input the beginning date in MM/
> DD/YY format.
> 2. Pop out another window to ask the user to input the ending date in
> MM/DD/YY format.
> 3. Then the macro deletes rows based on the entered date period (all
> rows between the beginning date and the ending date will be deleted).
>
> In the target excel worksheet, dates are recorded in column B.
>
> Can anyone help? Thanks!!!!!
>
>

 
Reply With Quote
 
bingshuo.li@gmail.com
Guest
Posts: n/a
 
      17th Nov 2008
Hi Mike and Ron,

Thank you two so much!! :-)

Regards,
B. Li



On Nov 17, 12:14*pm, Mike <M...@discussions.microsoft.com> wrote:
> Sub deleterows()
> On Error GoTo ErrHandler
> Dim startDate As Date
> Dim endDate As Date
> Dim rng As Range
> Dim i As Long
>
> startDate = InputBox("Enter Start Date as mm/dd/yy format")
> endDate = InputBox("Enter EndDate as mm/dd/yy format")
>
> Set rng = ActiveSheet.Range(Cells(1, "B"), Cells(Rows.Count, "B").End(xlUp))
>
> 'Work backwards from bottom to top when deleting rows
> With rng
> * * For i = .Rows.Count To 1 Step -1
> * * * * If .Cells(i).Value > startDate And .Cells(i).Value < endDate Then
> * * * * * * .Cells(i).EntireRow.delete
> * * * * End If
> * * Next i
> End With
> Exit Sub
> ErrHandler:
> * * Select Case Err.Number
> * * * * Case Is = 13
> * * * * * * MsgBox "Date is not in proper format"
> * * * * Case Else
> * * * * * * MsgBox "Error #" & Err.Number & vbCrLf & Err.Description
> * * End Select
> End Sub
>
> "bingshuo...@gmail.com" wrote:
> > Hi,

>
> > I am very new to VBA programming and I need help.

>
> > I am thinking to write a macro which can -
> > 1. Pop out a window to ask the user to input the beginning date in MM/
> > DD/YY format.
> > 2. Pop out another window to ask the user to input the ending date in
> > MM/DD/YY format.
> > 3. Then the macro deletes rows based on the entered date period (all
> > rows between the beginning date and the ending date will be deleted).

>
> > In the target excel worksheet, dates are recorded in column B.

>
> > Can anyone help? Thanks!!!!!


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Certain Rows Based on User Input kmzito@gmail.com Microsoft Excel Programming 1 12th May 2009 01:03 AM
Macro to delete rows based on date PMBO Microsoft Excel Misc 4 18th Feb 2009 01:50 PM
Delete rows based on date criteria Rookie_User Microsoft Excel Programming 1 12th Nov 2008 07:17 PM
Hide Rows and Columns based on Date Input LROCCO Microsoft Excel Discussion 6 12th Jun 2008 02:30 PM
Re: delete based on date in input box Bob Phillips Microsoft Excel Programming 0 5th Jan 2007 02:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:09 PM.