+ Reply to Thread
Results 1 to 4 of 4

Help with Compiling Excel Spreadsheet Data into One Table

Hybrid View

excelatlife Help with Compiling Excel... 08-20-2012, 03:40 PM
Mordred Re: Help with Compiling Excel... 08-20-2012, 04:14 PM
watersev Re: Help with Compiling Excel... 08-20-2012, 04:44 PM
Cutter Re: Help with Compiling Excel... 08-20-2012, 07:50 PM
  1. #1
    Registered User
    Join Date
    08-20-2012
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    1

    Help with Compiling Excel Spreadsheet Data into One Table

    Hi everyone, having trouble with one line of code. I think I'm pretty close to figuring out this macro. I'm getting the following error:
    "Run-time error '438':
    Object doesn't support this property or method"
    on this line of code: wbMstr.wsMstr.Range("c1").End(xlDown).Offset(1, 0).Select

    How can I better define my method? Thanks!


    Sub ImportCSVsWithReference()
    
    'Summary:   Import all CSV files from a folder into a single sheet
    '           adding a field in column A listing the CSV filenames
    
    Dim wbCSV   As Workbook
    Dim wbMstr  As Workbook:    Set wbMstr = ThisWorkbook
    Dim wsMstr  As Worksheet:   Set wsMstr = ThisWorkbook.Sheets("Sheet1")
    Dim fPath   As String:      fPath = "C:\Users\Eddie\Dropbox\Admob pull Data\Admob pull Data(eddie)\8.17\"    'path to CSV files, include the final \
    Dim fCSV    As String
    
    'If MsgBox("Clear the existing MasterCSV sheet before importing?", vbYesNo, "Clear?") _
        '= vbYes Then wsMstr.UsedRange.Clear
    
    Application.ScreenUpdating = True  'speed up macro
    
    fCSV = Dir(fPath & "*.csv")         'start the CSV file listing
    
        Do While Len(fCSV) > 0
          'open a CSV file
            Set wbCSV = Workbooks.Open(fPath & fCSV)
            wbCSV.ActiveSheet.Range(Range("a3:h3"), Range("a3").End(xlDown)).Copy
            wbMstr.wsMstr.Range("c1").End(xlDown).Offset(1, 0).Select
            
            wbCSV.Close False
          'ready next CSV
            fCSV = Dir
        Loop
     
    Application.ScreenUpdating = True
    End Sub
    Last edited by Cutter; 08-20-2012 at 07:50 PM. Reason: Added code tags

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Help with Compiling Excel Spreadsheet Data into One Table

    Hi excelatlife, are you looking to copy/paste/transfer values from the csv to the master? If so, try:
    Option Explicit
    
    Sub ImportCSVsWithReference()
    
    'Summary: Import all CSV files from a folder into a single sheet
    ' adding a field in column A listing the CSV filenames
    
        Dim wbCSV As Workbook
        Dim wbMstr As Workbook: Set wbMstr = ThisWorkbook
        Dim wsMstr As Worksheet: Set wsMstr = ThisWorkbook.Sheets("Sheet1")
        Dim fPath As String: fPath = "C:\Users\Eddie\Dropbox\Admob pull Data\Admob pull Data(eddie)\8.17\" 'path to CSV files, include the final \"
        Dim fCSV As String
        Dim cSel As Range
        Dim pstSel As Range, cpySel As Range
        'If MsgBox("Clear the existing MasterCSV sheet before importing?", vbYesNo, "Clear?") _
         '= vbYes Then wsMstr.UsedRange.Clear
        Dim rCnt As Long, cCnt As Long
        Application.ScreenUpdating = False    'Set to false to speed up macro
    
        fCSV = Dir(fPath & "*.csv")    'start the CSV file listing
    
        Do While Len(fCSV) > 0
            'open a CSV file
            Set wbCSV = Workbooks.Open(fPath & fCSV)
            Set cpySel = wbCSV.ActiveSheet.Range(Range("a3:h3"), Range("a3").End(xlDown))
            rCnt = cpySel.Rows.Count
            cCnt = cpySel.Columns.Count
            Set pstSel = wsMstr.Range(wsMstr.Cells(wsMstr.Rows.Count, 3).End(xlUp).Offset(1, 0), wsMstr.Cells(wsMstr.Rows.Count, cCnt).End(xlUp).Offset(rCnt + 1, 0))
            pstSel.Cells.Value = cpySel.Cells.Value
            Debug.Print pstSel.Address
            wbCSV.Close False
            'ready next CSV
            fCSV = Dir
        Loop
    
        Application.ScreenUpdating = True
    End Sub
    By the way, please note my usage of code tags around my code. See the forum rules regarding how to apply them. Otherwise, one of the moderators will get you!
    Last edited by Mordred; 08-20-2012 at 04:26 PM.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Help with Compiling Excel Spreadsheet Data into One Table

    Quote Originally Posted by excelatlife View Post
    Hi everyone, having trouble with one line of code. I think I'm pretty close to figuring out this macro. I'm getting the following error:
    "Run-time error '438':
    Object doesn't support this property or method"
    on this line of code: wbMstr.wsMstr.Range("c1").End(xlDown).Offset(1, 0).Select

    How can I better define my method? Thanks!
    Hi excelatlife,

    The cause of the error is that your C column is empty and instruction xlDown gets you to the very last row of the sheet and afterwards you want another row beyond the sheet limit - Excel starts screaming.
    Last edited by watersev; 08-20-2012 at 04:46 PM.

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Help with Compiling Excel Spreadsheet Data into One Table

    @ excelatlife

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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