Hi All,
I have a code that works pretty good, but if a user enters a date in the input box that does not match the data I'm filtering it keeps looping. I tried IsEmpty, but with no luck. If the data that is being filtered is outside my date range and the filter is Null. My macro keeps looping. I've attached the code below - Help would be greatly appreciated. Thanks -
Option Explicit
Sub FilterCurrentDate()
Dim a, b, mydate
mydate = InputBox("Enter Your Value Date"
If Len(mydate) = 0 Then
'it will exit sub if you hit Cancel Button on the Excel File
Else
Columns("A:I"
.Select
Selection.ClearContents
Windows("Me.xls"
.Activate
Columns("C:C"
.Select
Selection.NumberFormat = "mm/dd/yy"
Range("A1"
.Select
a = "=" & Format(mydate, "mm/dd/yy"
b = ">" & Format(mydate, "mm/dd/yy"
Selection.AutoFilter Field:=3, Criteria1:=a, Operator:=xlOr, _
Criteria2:=b
End If
End Sub
Sub PastMyData()
Dim rngRow As Range, rngCol As Range, ws As Worksheet, lRow As Long
Dim r As Variant, c As Variant
FilterCurrentDate
Set ws = Workbooks("NewFile.xls"
.Worksheets("Summary"
lRow = 1
With Workbooks("Me"
.Worksheets("Data"
Set rngRow = Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
Set rngCol = Range(.Cells(1, 1), .Cells(1, 1).End(xlToRight))
For Each r In rngRow.SpecialCells(xlCellTypeVisible)
For Each c In rngCol
ws.Cells(lRow, c.Column).Value = .Cells(r.Row, c.Column).Value
Next
lRow = lRow + 1
Next
End With
End Sub
I have a code that works pretty good, but if a user enters a date in the input box that does not match the data I'm filtering it keeps looping. I tried IsEmpty, but with no luck. If the data that is being filtered is outside my date range and the filter is Null. My macro keeps looping. I've attached the code below - Help would be greatly appreciated. Thanks -
Option Explicit
Sub FilterCurrentDate()
Dim a, b, mydate
mydate = InputBox("Enter Your Value Date"
If Len(mydate) = 0 Then
'it will exit sub if you hit Cancel Button on the Excel File
Else
Columns("A:I"
Selection.ClearContents
Windows("Me.xls"
Columns("C:C"
Selection.NumberFormat = "mm/dd/yy"
Range("A1"
a = "=" & Format(mydate, "mm/dd/yy"
b = ">" & Format(mydate, "mm/dd/yy"
Selection.AutoFilter Field:=3, Criteria1:=a, Operator:=xlOr, _
Criteria2:=b
End If
End Sub
Sub PastMyData()
Dim rngRow As Range, rngCol As Range, ws As Worksheet, lRow As Long
Dim r As Variant, c As Variant
FilterCurrentDate
Set ws = Workbooks("NewFile.xls"
lRow = 1
With Workbooks("Me"
Set rngRow = Range(.Cells(1, 1), .Cells(1, 1).End(xlDown))
Set rngCol = Range(.Cells(1, 1), .Cells(1, 1).End(xlToRight))
For Each r In rngRow.SpecialCells(xlCellTypeVisible)
For Each c In rngCol
ws.Cells(lRow, c.Column).Value = .Cells(r.Row, c.Column).Value
Next
lRow = lRow + 1
Next
End With
End Sub