+ Reply to Thread
Results 1 to 5 of 5

Macro issues, copying from csv to xls template and then refreshing pivot

  1. #1
    Registered User
    Join Date
    04-09-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    2

    Unhappy Macro issues, copying from csv to xls template and then refreshing pivot

    Hi,

    Please tell me there is an Excel Rockstar out there that can help with a macro that's giving me trouble!

    I was hoping for the following code to:
    - open a specific csv file (called RAW.csv)
    - copy data from that same .csv file
    - open an xls template (that includes formulas on sheet 1 and a pivot on sheet 2)
    - paste the data from the csv file to the xls template on sheet 1 (called data)
    - and go to sheet 2 on the xls template (called pivot) and refresh the pivot

    The code I'm using opens both files but there is a "Run time error 9" before the task is complete, please advise.

    Sub MACROattempt4()
    '
    '
    Workbooks.Open Filename:= _
    "Q:\Reports\Daily \OUT DATA\RAW.csv"
    Range("A1:R2000").Select
    Selection.Copy
    Workbooks.Open Filename:= _
    "Q:\Reports\Daily \IN DATA\BLANK.xlsm"
    Windows("BLANK.xlsm").Activate
    Sheets("data").Select
    Range("A1").Select
    ActiveSheet.Paste
    Sheets("Pivot").Select
    ActiveSheet.PivotTables("PivotTable3").PivotCache.Refresh
    Workbooks("RAW.csv").Close
    Workbooks("BLANK.xlsm").Close
    End Sub


    Any advise is greatly appreciated!

    DATAN4113

  2. #2
    Valued Forum Contributor abduljaleel.mca's Avatar
    Join Date
    02-13-2013
    Location
    Chennai, India
    MS-Off Ver
    MS 365 Business
    Posts
    326

    Re: Macro issues, copying from csv to xls template and then refreshing pivot

    Can u try this one

    Please Login or Register  to view this content.
    instead of

    Please Login or Register  to view this content.
    I don't see anything wrong with the other lines.
    Last edited by abduljaleel.mca; 04-11-2013 at 06:20 AM.

  3. #3
    Registered User
    Join Date
    04-09-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro issues, copying from csv to xls template and then refreshing pivot

    Thanks so much for your review!

    Unfortunately, I'm still receiving "Run time error 9".

    Both docs open ok and the selection is copied.

    However, I stepped through the code and found the error is generated at "Windows("BLANK.xlsm").Activate" - which seems a little odd.

    Any idea why that would create an issue?

    DATAN4113

  4. #4
    Registered User
    Join Date
    04-15-2013
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro issues, copying from csv to xls template and then refreshing pivot

    why don't you try opening up the two workbooks first

    then follow up with selection of the workbook to copy the file from

    workbooks.("RAW.csv").activate
    sheets("nameofthesheetyouneedtocopy").select
    range("A1:R2000").select
    selection.copy
    workbooks("BLANK.xlsm").activate
    sheets("nameofthesheetyouwanttopaste").select
    range("A1").select
    activesheet.paste

    follow up with your code of sheets to pivot

  5. #5
    Valued Forum Contributor abduljaleel.mca's Avatar
    Join Date
    02-13-2013
    Location
    Chennai, India
    MS-Off Ver
    MS 365 Business
    Posts
    326

    Re: Macro issues, copying from csv to xls template and then refreshing pivot

    Please make sure below file name with the .xlsm extension is exists in the path you specified above.

    BLANK.xlsm

    "Windows("BLANK.xlsm").Activate" is working here for me as I have this file with the .xlsm extension.
    Last edited by abduljaleel.mca; 04-18-2013 at 01:43 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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