VBA Runtime Error

Johnny4strings

New Member
Joined
Nov 9, 2018
Messages
33
Hello Everyone,

I am having a slight issue with some code I am trying to run.
Some backstory: This VBA is from a spreadsheet that creates some tabs when executing the macro/clicking on macro button with the ultimate goal of pulling text from a .txt that is updated daily. This code is part of a larger set of data that pulls more tabs/data-I just wanted to post the information that was triggering the debugger.

As of now I am getting 1004 error message upon execute of macro: Application-defined or object defined error. Error where debugger has identified the problem is bolded. Code begins below dotted lines. As always, thank you gurus in advance :)

…………………………………………………………………
Code:
'FM1 Data add
On Error Resume Next
Sheets("FM1 " & Format(Now, "mm.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now, "m.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now - 1, "mm.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now - 1, "m.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now - 2, "mm.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now - 2, "m.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now - 3, "mm.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now - 3, "m.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now - 4, "mm.dd.yy")).Visible = True
Sheets("FM1 " & Format(Now - 4, "m.dd.yy")).Visible = True
On Error GoTo 0
 
On Error Resume Next
Sheets("FM1 " & Format(Now, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now, "m.dd.yy")).Select
Sheets("FM1 " & Format(Now - 1, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now - 1, "m.dd.yy")).Select
Sheets("FM1 " & Format(Now - 2, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now - 2, "m.dd.yy")).Select
Sheets("FM1 " & Format(Now - 3, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now - 3, "m.dd.yy")).Select
Sheets("FM1 " & Format(Now - 4, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now - 4, "m.dd.yy")).Select
On Error GoTo 0
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete
Range("A2").Select
 
 
    ActiveWorkbook.Worksheets.Add
    ActiveSheet.Name = "FM1 Data Retrieval"
    On Error GoTo Errorhandler
    'File Path: FM1 (Within Quotations)
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;File:///\\drivepath\FM1.txt", _
        Destination:=Range("$A$1"))
               .Name = "FM1"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    On Error GoTo 0
    Cells.Find(What:="Fund Code", After:=ActiveCell, LookIn:= _
    xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate
    ActiveCell.Offset(1, 0).Select
    Range(Selection, Selection.End(xlDown)).Select
    FundCount = Selection.Count
    ActiveCell.Select
    For X = 1 To FundCount
    ActiveCell.Value = Trim(Selection.Value)
    ActiveCell.Offset(1, 0).Select
 
Next X
 
Range("A2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Cut
On Error Resume Next
Sheets("FM1 " & Format(Now, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now, "m.dd.yy")).Select
Sheets("FM1 " & Format(Now - 1, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now - 1, "m.dd.yy")).Select
Sheets("FM1 " & Format(Now - 2, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now - 2, "m.dd.yy")).Select
Sheets("FM1 " & Format(Now - 3, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now - 3, "m.dd.yy")).Select
Sheets("FM1 " & Format(Now - 4, "mm.dd.yy")).Select
Sheets("FM1 " & Format(Now - 4, "m.dd.yy")).Select
On Error GoTo 0
ActiveSheet.Paste
Application.DisplayAlerts = False
Sheets("FM1 Data Retrieval").Delete
ActiveSheet.Name = "FM1 " & Format(Now, "mm.dd.yy")
Application.DisplayAlerts = True
Range("A2").Select
Selection.End(xlToRight).Select
[B]ActiveCell.Offset(0, 1).Select[/B]
ActiveCell.Value = "=LEFT(TRIM($J2),2)"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "=TRIM(LEFT($I2,8))"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "=IF(LEFT($S2,4)=" & """RC17""" & "," & """Y""" & "," _
& """N""" & ")"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "=RIGHT($S2,2)"
Selection.End(xlToLeft).Select
Selection.End(xlDown).Select
Selection.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
 Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.FillDown
 
Last edited by a moderator:
...Its funny but the other forms I am pulling data from are not throwing 1004 errors, just this one for some reason. Seems like the macro passes the first form fine then gets hung up on the second form (the form I sent the VBA from). I have a third form to pass date from however I am uncertain if that "data pull" is functional or not at this point.
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi it does appear that the data is being transferred from the remote drive and that the spreadsheet is creating the individual tabs and populating them with data. I am not required to paste anything as tabs are created with the macro; its just that a run time error keeps revealing itself and possibly causing issues.
 
Upvote 0
Shortly before you get the error, your code is pasting data to the active sheet. Is the data getting pasted & is it all the data?
 
Upvote 0
Hi and thank you for replying. I do believe that this is in fact pasting all information to the worksheet. I worked with this last night and I think I have found the problem with the macro dropping me off at cell XDF2; the macro seems to be working fine now and as far as I can tell, the data is accurate. Fluff, than you SO much for your help and more importantly, time.
-John
 
Upvote 0
Glad you got it sorted & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top