bjohnson2235
New Member
- Joined
- Jun 16, 2021
- Messages
- 2
- Office Version
- 2016
- Platform
- Windows
Hello,
I have a macro that worked fine for a month and a half, but is now giving me a 1004 Runtime error "Application-defined or object defined error". Below is the code in which the macro is errors out on.
The gist of the macro is to filter by a date provided by the user, then filter by a fixed column on that date. Where the error then occurs is when the macro goes to a column "T", and tries to find the first visible row. The code is in a form, and works well on one option of the form, but not this option.
I have a macro that worked fine for a month and a half, but is now giving me a 1004 Runtime error "Application-defined or object defined error". Below is the code in which the macro is errors out on.
The gist of the macro is to filter by a date provided by the user, then filter by a fixed column on that date. Where the error then occurs is when the macro goes to a column "T", and tries to find the first visible row. The code is in a form, and works well on one option of the form, but not this option.
VBA Code:
'Gets the date
Dim Start_date As Integer
Dim UserEntry As String
Dim Msg As String
Dim TheDate As String
Msg = "Enter Wire Journal date for processing (MM/DD/YYYY)"
Do
UserEntry = InputBox(Msg)
If UserEntry = "" Then Exit Sub
If IsDate(UserEntry) Then
ActiveSheet.Range("AI1").Value = Format(UserEntry, "mm/dd/yyyy")
Else
Msg = "Please try again. Enter date as mm/dd/yyyy"
End If
Exit Do
Loop
'Filters by the date entered in AI1, filters by deposit date
ActiveSheet.Range("$A$1:$AA$1").End(xlDown).AutoFilter Field:=26, Criteria1:= _
"=" & Range("AI1"), Operator:=xlAnd
'Filters by Receipt Applied
Sheets("Wires").Select
Dim A As Range, Z As Integer
Set A = Range(Range("$A$1:$AA$1"), Range("$A$1:$AA$1").End(xlDown))
A.AutoFilter Field:=13, Criteria1:="Receipt Applied"
Z = WorksheetFunction.Count(A.Cells.SpecialCells(xlCellTypeVisible))
If Z = 0 Then
MsgBox "There are no items with a status of Receipt Applied. Update the Wires tab and re-run the Macro"
Else
'Finds the first visible row in Column T for Receivable ID
Sheets("Wires").Select
With Worksheets("Wires").AutoFilter.Range
[COLOR=rgb(184, 49, 47)] Range("T" & .Offset(1, 0).SpecialCells(xlCellTypeVisible)(1).Row).Select ' This is the row that causes the 1004 error[/COLOR]
End With
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy