+ Reply to Thread
Results 1 to 9 of 9

Autofill Filename to end of row

  1. #1
    Registered User
    Join Date
    03-03-2016
    Location
    nashville, TN
    MS-Off Ver
    2007
    Posts
    24

    Autofill Filename to end of row

    I have a script that extracts the filename from a file stored on a SharePoint site. It all works properly but I need the script to autofill the file name down to the last row. What am I missing?
    The last line in this code is when the filename gets populated on the first cell in destination file, I need it to fill down all rows in the column to last row

    [CODE]Dim SummarySheet As Worksheet
    Dim FolderPath As String
    Dim NRow As Long
    Dim FileName As String
    Dim imgTitle As String
    Dim WorkBk As Workbook
    Dim SourceRange As Range
    Dim DestRange As Range
    Dim FolderName As String
    Dim LR As Long
    Dim x As Long
    Dim n As Integer
    Dim temp As Long
    Dim rng As Range, ar As Range
    Dim nr As Range
    Dim mr As Range
    Dim LoginName As String
    Dim WinShuttle As Application
    Dim Connection As Object
    Dim session As Object
    Dim SAPApp As Object
    Dim SAPCon As Object, SAPSesi As Object
    Dim SAPGUIAuto As Object
    Dim sapConnection As Object
    Dim d As String, ext, y
    Dim srcPath As String, destPath As String, srcFile As String
    Application.ScreenUpdating = False



    LoginName = UCase(GetUserID)

    'Designates Sheet for pasting from multiple workbooks
    Set SummarySheet = Worksheets(3)


    'Modify folder path when transferring between process owners
    FolderPath = "Z:\"

    'Nrow keeps track of where to insert new rows in the workbook
    NRow = 1
    LR = ActiveSheet.Range("U" & Rows.Count).End(xlUp).Row
    'Call directory the first time pointing it to all excel files
    FileName = Dir(FolderPath & "*.xls*")
    'Loop until directory returns empty string
    Do While FileName <> ""
    'Open a workbook in the folder
    Set WorkBk = Workbooks.Open(FolderPath & FileName)

    'Set the cell in column U to house the file name
    SummarySheet.Range("U:U" & NRow).Value = FileName


    'Set the range to be A1000 through W1000
    On Error Resume Next
    Set SourceRange = WorkBk.Worksheets(1).Range("A2:M300")
    On Error GoTo 0
    'Set the destination range
    Set DestRange = SummarySheet.Range("A" & NRow)
    Set DestRange = DestRange.Resize(SourceRange.Rows.Count, SourceRange.Columns.Count)

    'Copy over values from the source to the destination
    DestRange.Value = SourceRange.Value
    SummarySheet.Range("U").AutoFill Destination:=Range("U1:U" & LR)[/CODE]

  2. #2
    Registered User
    Join Date
    03-03-2016
    Location
    nashville, TN
    MS-Off Ver
    2007
    Posts
    24

    Re: Autofill Filename to end of row

    Wrong line in previous post, this is the correct line

    Please Login or Register  to view this content.

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Autofill Filename to end of row

    Would it not be
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    even this may have to be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-03-2016
    Location
    nashville, TN
    MS-Off Ver
    2007
    Posts
    24

    Re: Autofill Filename to end of row

    I tries that & got a Method 'Range' of object'_Global failed error

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Autofill Filename to end of row

    Quote Originally Posted by bennyamy View Post
    I tries that & got a Method 'Range' of object'_Global failed error
    Oh, what did you try?

  6. #6
    Registered User
    Join Date
    03-03-2016
    Location
    nashville, TN
    MS-Off Ver
    2007
    Posts
    24

    Re: Autofill Filename to end of row

    I tried what you suggested before originally posting this.

  7. #7
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,482

    Re: Autofill Filename to end of row

    I find your lack of detail disturbing....

  8. #8
    Registered User
    Join Date
    03-03-2016
    Location
    nashville, TN
    MS-Off Ver
    2007
    Posts
    24

    Re: Autofill Filename to end of row

    I tried what is shown below & received this error: Method 'Range' of object'_Global failed error


    Formula:
    Please Login or Register  to view this content.

    even this may have to be:


    Formula:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    03-03-2016
    Location
    nashville, TN
    MS-Off Ver
    2007
    Posts
    24

    Re: Autofill Filename to end of row

    I also tried the below which copies the file name down but it copies over each file name

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Autofill Column J from J10 to Last Row, According to 4th to 11th Digits of Filename
    By Ernching in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2015, 02:28 AM
  2. Formula to return filename in folder based on partial filename
    By Rerock in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-26-2014, 12:28 PM
  3. [SOLVED] Runtime 1004 after prompting for filename but not when filename hard coded.
    By cgoodenough in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-04-2013, 03:46 AM
  4. [SOLVED] Find if filename exists and update variable within the filename structure
    By Lungfish in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-18-2013, 02:42 AM
  5. Replies: 0
    Last Post: 11-01-2012, 09:28 AM
  6. Code to create a custom .csv filename with version stamp in filename
    By Gti182 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-10-2012, 04:07 AM
  7. Replies: 3
    Last Post: 07-09-2012, 03:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1