PC Review


Reply
Thread Tools Rate Thread

Creating Parameter Fields

 
 
Naraine Ramkirath
Guest
Posts: n/a
 
      29th May 2007
Hello All,

I have a simple spreadsheet with approx 500 records. I would like to have
this data sorted by column D and delete all records that is outside of two
parameter dates. Question: how do I create a parameter field using VBA?



Naraine




 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      30th May 2007
Let's say your data is in cells D2100. There is a way to determine the
last row, but for now, I'll hard code it.

Sub Test()
Dim myRange As Range
Dim DeleteRange As Range
Dim r As Range

Set myRange = Range("D2100")

Set DeleteRange = Nothing
If r.Value > DateSerial(2007, 3, 1) Or r.Value < DateSerial(2007, 4, 1) Then
If DeleteRange Is Nothing Then
DeleteRange = r
Else
DeleteRange = Union(DeleteRange, r)
End If
End If

Application.DisplayAlerts = False
If Not DeleteRange Is Nothing Then
DeleteRange.EntireRow.Delete
End If
Application.DisplayAlerts = True
End Sub


Modify to suit. I've got it deleting the entire row. I'm not sure if
that's what you want or not.

HTH,
Barb Reinhardt
"Naraine Ramkirath" wrote:

> Hello All,
>
> I have a simple spreadsheet with approx 500 records. I would like to have
> this data sorted by column D and delete all records that is outside of two
> parameter dates. Question: how do I create a parameter field using VBA?
>
>
>
> Naraine
>
>
>
>
>

 
Reply With Quote
 
Naraine Ramkirath
Guest
Posts: n/a
 
      30th May 2007
Thank Barb. is there a way for these two dates to be prompted for data
entry? e.g.

If r.Value > [?begdate] Or r.Value < [?enddate] Then
.....

"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:58BBA086-7205-46C9-BC92-(E-Mail Removed)...
> Let's say your data is in cells D2100. There is a way to determine the
> last row, but for now, I'll hard code it.
>
> Sub Test()
> Dim myRange As Range
> Dim DeleteRange As Range
> Dim r As Range
>
> Set myRange = Range("D2100")
>
> Set DeleteRange = Nothing
> If r.Value > DateSerial(2007, 3, 1) Or r.Value < DateSerial(2007, 4, 1)

Then
> If DeleteRange Is Nothing Then
> DeleteRange = r
> Else
> DeleteRange = Union(DeleteRange, r)
> End If
> End If
>
> Application.DisplayAlerts = False
> If Not DeleteRange Is Nothing Then
> DeleteRange.EntireRow.Delete
> End If
> Application.DisplayAlerts = True
> End Sub
>
>
> Modify to suit. I've got it deleting the entire row. I'm not sure if
> that's what you want or not.
>
> HTH,
> Barb Reinhardt
> "Naraine Ramkirath" wrote:
>
> > Hello All,
> >
> > I have a simple spreadsheet with approx 500 records. I would like to

have
> > this data sorted by column D and delete all records that is outside of

two
> > parameter dates. Question: how do I create a parameter field using VBA?
> >
> >
> >
> > Naraine
> >
> >
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      30th May 2007
I'd use something like this'

Dim BegDate As Date
Dim EndDate As Date

BegDate = InputBox("Enter Begin Date:", Date1)

EndDate = InputBox("Enter End Date:", Date2)


"Naraine Ramkirath" wrote:

> Thank Barb. is there a way for these two dates to be prompted for data
> entry? e.g.
>
> If r.Value > [?begdate] Or r.Value < [?enddate] Then
> .....
>
> "Barb Reinhardt" <(E-Mail Removed)> wrote in message
> news:58BBA086-7205-46C9-BC92-(E-Mail Removed)...
> > Let's say your data is in cells D2100. There is a way to determine the
> > last row, but for now, I'll hard code it.
> >
> > Sub Test()
> > Dim myRange As Range
> > Dim DeleteRange As Range
> > Dim r As Range
> >
> > Set myRange = Range("D2100")
> >
> > Set DeleteRange = Nothing
> > If r.Value > DateSerial(2007, 3, 1) Or r.Value < DateSerial(2007, 4, 1)

> Then
> > If DeleteRange Is Nothing Then
> > DeleteRange = r
> > Else
> > DeleteRange = Union(DeleteRange, r)
> > End If
> > End If
> >
> > Application.DisplayAlerts = False
> > If Not DeleteRange Is Nothing Then
> > DeleteRange.EntireRow.Delete
> > End If
> > Application.DisplayAlerts = True
> > End Sub
> >
> >
> > Modify to suit. I've got it deleting the entire row. I'm not sure if
> > that's what you want or not.
> >
> > HTH,
> > Barb Reinhardt
> > "Naraine Ramkirath" wrote:
> >
> > > Hello All,
> > >
> > > I have a simple spreadsheet with approx 500 records. I would like to

> have
> > > this data sorted by column D and delete all records that is outside of

> two
> > > parameter dates. Question: how do I create a parameter field using VBA?
> > >
> > >
> > >
> > > Naraine
> > >
> > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
David Sisson
Guest
Posts: n/a
 
      30th May 2007
Sub DeleteAllBut()
Dim myRange As Range
Dim Date1 As Date
Dim Date2 As Date
Dim NumRows As Integer
Dim Counter As Integer

Set myRange = Range("D2" &
ActiveSheet.Range("D65536").End(xlUp).Row)

NumRows = myRange.Rows.Count

'No error checking here. If you put in a weird date, Excel will try
to interpret
'whatever you type in and you could end up deleting everything.
Date1 = InputBox("Enter starting date: ", "Starting Date")
Date2 = InputBox("Enter ending date: ", "Ending Date")

For Counter = NumRows + 1 To 1 Step -1

If Range("D" & Counter).Value < Date1 Or Range("D" & Counter).Value >
Date2 Then
Range("D" & Counter).EntireRow.Delete
End If
Next Counter

End Sub

 
Reply With Quote
 
Naraine Ramkirath
Guest
Posts: n/a
 
      30th May 2007
David,

works perfectly. Thank you!


"David Sisson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Sub DeleteAllBut()
> Dim myRange As Range
> Dim Date1 As Date
> Dim Date2 As Date
> Dim NumRows As Integer
> Dim Counter As Integer
>
> Set myRange = Range("D2" &
> ActiveSheet.Range("D65536").End(xlUp).Row)
>
> NumRows = myRange.Rows.Count
>
> 'No error checking here. If you put in a weird date, Excel will try
> to interpret
> 'whatever you type in and you could end up deleting everything.
> Date1 = InputBox("Enter starting date: ", "Starting Date")
> Date2 = InputBox("Enter ending date: ", "Ending Date")
>
> For Counter = NumRows + 1 To 1 Step -1
>
> If Range("D" & Counter).Value < Date1 Or Range("D" & Counter).Value >
> Date2 Then
> Range("D" & Counter).EntireRow.Delete
> End If
> Next Counter
>
> End Sub
>



 
Reply With Quote
 
Naraine Ramkirath
Guest
Posts: n/a
 
      30th May 2007
Barb,

thank you. it worked.
"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:52D8B4C5-6F9F-4EDF-8F1D-(E-Mail Removed)...
> I'd use something like this'
>
> Dim BegDate As Date
> Dim EndDate As Date
>
> BegDate = InputBox("Enter Begin Date:", Date1)
>
> EndDate = InputBox("Enter End Date:", Date2)
>
>
> "Naraine Ramkirath" wrote:
>
> > Thank Barb. is there a way for these two dates to be prompted for data
> > entry? e.g.
> >
> > If r.Value > [?begdate] Or r.Value < [?enddate] Then
> > .....
> >
> > "Barb Reinhardt" <(E-Mail Removed)> wrote in

message
> > news:58BBA086-7205-46C9-BC92-(E-Mail Removed)...
> > > Let's say your data is in cells D2100. There is a way to determine

the
> > > last row, but for now, I'll hard code it.
> > >
> > > Sub Test()
> > > Dim myRange As Range
> > > Dim DeleteRange As Range
> > > Dim r As Range
> > >
> > > Set myRange = Range("D2100")
> > >
> > > Set DeleteRange = Nothing
> > > If r.Value > DateSerial(2007, 3, 1) Or r.Value < DateSerial(2007, 4,

1)
> > Then
> > > If DeleteRange Is Nothing Then
> > > DeleteRange = r
> > > Else
> > > DeleteRange = Union(DeleteRange, r)
> > > End If
> > > End If
> > >
> > > Application.DisplayAlerts = False
> > > If Not DeleteRange Is Nothing Then
> > > DeleteRange.EntireRow.Delete
> > > End If
> > > Application.DisplayAlerts = True
> > > End Sub
> > >
> > >
> > > Modify to suit. I've got it deleting the entire row. I'm not sure

if
> > > that's what you want or not.
> > >
> > > HTH,
> > > Barb Reinhardt
> > > "Naraine Ramkirath" wrote:
> > >
> > > > Hello All,
> > > >
> > > > I have a simple spreadsheet with approx 500 records. I would like to

> > have
> > > > this data sorted by column D and delete all records that is outside

of
> > two
> > > > parameter dates. Question: how do I create a parameter field using

VBA?
> > > >
> > > >
> > > >
> > > > Naraine
> > > >
> > > >
> > > >
> > > >
> > > >

> >
> >
> >



 
Reply With Quote
 
IanKR
Guest
Posts: n/a
 
      1st Jun 2007
> I have a simple spreadsheet with approx 500 records. I would like to
> have this data sorted by column D and delete all records that is
> outside of two parameter dates. Question: how do I create a parameter
> field using VBA?


Did you receive my e-mail on this?


 
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
Parameter box to look up information in two fields (Fields are in separate table radiaz via AccessMonster.com Microsoft Access Forms 0 3rd Mar 2006 12:10 AM
Auto creating text fields when creating new slide. =?Utf-8?B?amFtZXM=?= Microsoft Powerpoint 1 16th Jun 2005 04:02 PM
Additional fields for form based parameter query/null fields =?Utf-8?B?Z2Vla3Nkb2l0YmV0dGVy?= Microsoft Access Queries 2 7th Jan 2005 10:05 PM
Re: Parameter Query on two fields Nikos Yannacopoulos Microsoft Access Queries 1 8th Apr 2004 01:46 PM
parameter query on two fields Tom Nichol Microsoft Access Queries 1 8th Apr 2004 02:27 AM


Features
 

Advertising
 

Newsgroups
 


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