PDA

View Full Version : Solved: Using forms and form data



marshybid
04-28-2008, 01:26 AM
Morning All,

I am currebtly filtering out certain rows of data based on one criteria which is fixed (see code below).

I would like to beable to add another criteria which is variable and therfore needs to be manually entered, probably via a form. This data will be two dates - start date and end date. I have no experience of using forms, so could anyone please help.

Current Code =



'// Delete non required data from each worksheet
Sheets("Approved Timesheets").Select
Set myBaseWorkSheet = ActiveWorkbook.ActiveSheet
Set myBaseRange = myBaseWorkSheet.Rows
For RowsCounter = myBaseRange.Rows.Count To 2 Step -1
Set myBaseRow = myBaseRange.Item(RowsCounter)
If Len(myBaseRow.Cells.Item(1, 1)) <> 0 Then

'// Delete data that we do not need for each tab
If myBaseRow.Cells.Item(1, 21) <> "Approved" Then

myBaseRow.Delete

End If
End If
Next


I know that I need to add in another If statement - If myBaseRow.Cells.Item(1, 46) >=Start Date and <=End date Then

Thanks in advance

Marshybid

Bob Phillips
04-28-2008, 01:34 AM
Just use Inputbox to get a start and end date, no need for a form.

marshybid
04-28-2008, 01:46 AM
Hi xld,

How would I use that?

Here is the code I have initially in my macro;



Dim myWorkBook As Workbook
Dim myBaseWorkSheet As Worksheet
Dim myBaseRange As Range
Dim myBaseRow As Range
Dim RowsCounter As Long
Dim WeDate As String


How would I add an input box for Start Date and End Date and then read those in my If statement?

Sorry to be naive about this.

On another note, did you see that I reposted an updated spreadsheet and a response to your query for

http://www.vbaexpress.com/forum/showthread.php?t=19181

How to create a table of missing items :bow:

Your a life saver

Marshybid

Bob Phillips
04-28-2008, 02:15 AM
Dim StartDate As Date
Dim EndDate As Date

On Error Resume Next
StartDate = Application.InputBox("Enter start date", Type:=2)
On Error GoTo 0
If StartDate > 0 Then

On Error Resume Next
EndDate = Application.InputBox("Enter end date", Type:=2)
On Error GoTo 0
If EndDate > 0 Then

If EndDate < StartDate Then

MsgBox "Start date not earliuer than end date"
Else

'rest of code
End If
End If
End If

marshybid
04-28-2008, 03:27 AM
Thanks xld. I will mark this as solved