I have a file that I get everyday/everyweek. First I test if the file is available in the directory, if it is not then I go to "data tracker" and make value of Range B2 "Missing" in that sheet. I am getting a
run time error 1004
in that section. Please help.
If the file is available then I need to copy B2 of the opening workbook and I need to paste it into my macro book Column A, if Column A already have values then it will paste in the next available/empty cell/row in column A of my macro book. That section might be wrong too, hoping an expert can help.
Application.AskToUpdateLinks = False
Application.ScreenUpdating = False
Dim FilePath As String
Dim TestStr As String
Dim WBA As Workbook 'Opened Workbook
FilePath = "C:\Users\anthonyer\Documents\Automation VBA\Source\Comcast Secondary"
TestStr = ""
On Error Resume Next
TestStr = Dir(FilePath)
On Error GoTo 0
If TestStr = "" Then
Workbooks("FullAuto Final.xlsm").Activate
Worksheets("Data Tracker").Range("B2").Select
Selection.Value = "Missing"
Else
Workbooks.Open "C:\Users\anthonyer\Documents\Automation VBA\Source\Comcast Secondary"
Set WBA = ActiveWorkbook
WBA.Application.CutCopyMode = False
'Select and Copy Site Name
WBA.Sheets(1).Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy Destination:=ThisWorkbook.Worksheets(1).Range("A:A" & Cells(Rows.Count, "A:A").End(xlUp).Row)
WBA.Close SaveChanges:=False
ThisWorkbook.Activate
Worksheets("Data Tracker").Range("A2").Value = "Complete"
End If
Application.AskToUpdateLinks = True
Application.ScreenUpdating = True
End Sub
Workbooks("FullAuto Final.xlsm").Worksheets("Data Tracker").Range("B2").Value = "Missing"? (You should avoid usingSelectwhenever possible. It leads to too many issues.)TestStr = Dir(FilePath)toTestStr = Dir(FilePath & "\*.*")otherwise it won't find any files to process. (But that doesn't explain why you are getting the error when it correctly/incorrectly decides that there are no files to process.)