+ Reply to Thread
Results 1 to 14 of 14

Code to Change Data Source for an online shared file, with out using the online link?

  1. #1
    Registered User
    Join Date
    04-29-2017
    Location
    Midwest
    MS-Off Ver
    Office 365
    Posts
    32

    Code to Change Data Source for an online shared file, with out using the online link?

    I have been working on a Sheet for use at work, that will eventually be spread to multiple offices
    Every office will have its own set of data to use.
    basically, it sorts it to a Pivot table

    Macro I made to automate the time consuming task, in general works great, but needs to have the Data Source refreshed every time...
    What happens is it seems to not know to refresh the entire data set... I dont know how to describe it other than if I only have 1400 lines in the data set after initial sorting and removing of extra data by using my macro, the next time the data is refreshed, it only looks at that same 1400 lines
    and I need it to change the Pivot data set to look at about 5000 lines every time I run the macro

    Right now when I create a Macro and Just do it manually to see what it does, I get this

    Range("A2").Select
    ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
    PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "https://filelocation.com/personal/online_com/Documents/[Report In-Out.xlsm]QC Outbound!R1C1:R5000C13" _
    , Version:=6)
    Sheets("QC Outbound").Select

    but becasue this will be shared by many offices, and each office uses their own online location, I need it to be generic and not include a web link..

    Is there an "Active sheet" type of command I can put in to update the Pivot data source instead of the full file location?

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    What will they be connecting to? Another workbook an Access File or CSV file?
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Registered User
    Join Date
    04-29-2017
    Location
    Midwest
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    Quote Originally Posted by dflak View Post
    What will they be connecting to? Another workbook an Access File or CSV file?
    Their own version of this worksheet

    Microsoft Sharepoint One Drive File

    they will be Downloading a Hard Copy every Day, making changes to the base set of data, then saving it and it auto uploads...

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    Here is a different way of doing it. Instead of trying to change the connection to a different external source, design the workbook to work off a local table in the workbook, but populate this table with a user-defined path, file and sheet name.

    The attached workbook has a Control Panel sheet that lets the user define the path, file name and sheet name to the office data source. If a sheet name is not defined (blank cell), Sheets (1) is assumed. This workbook should work with any kind of an Excel Spreadsheet or a CSV file.

    You can use this workbook.Redefine the table on the Data Sheet to match the format of your data. Basically, type in new headers. Then modify the pivot table on the Pivot Sheet. Mail this workbook to the offices. They fill in the path, file and sheet names and click on the Get Data button. Unless the information changes, they only have to fill in the information once.

    One of the advantages of using a flexible table like this is that if you need helper columns, the table will remember the helper formulas and copy them down as the new data are imported. You can hide the data sheet if you wish. Once you have the names filled in on the Control Panel, you can copy / paste the Get Data button to the Pivot Table sheet and hide the Control Panel sheet.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-29-2017
    Location
    Midwest
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    Sorry, That does not work for my application
    I need it to do something specific as I have described...
    I just need the VBA code to generically update the Excel sheet pivot table data so I can tell it to update it locally instead of telling it to use the original source from online


    I'll explain the sheet so you can have a better understanding

    Our company has 35 offices worldwide, each with a different set of equipment(or as I will say, "Gear") needs every day
    we have customers that request gear, we package it, rent it to them, then they return it
    if they need something that is not in their current location, we truck it in

    Daily our list of outgoing and Incoming Gear Changes at each location
    the main tracking software we use can spit out a list with all of teh incoming and outgoing gear...(but it is a large list with ALL of the different departments all at once)
    we take that list, and copy/paste it into a worksheet, which sorts it into a pivot table...

    basically drop data into Sheet1(outgoing gear) and Sheet2(Incoming Gear), sort with a macro to get rid of things not used/needed by our department
    the problems that happens, is that the data set size changes each day, and becasue we filter and delete lines, the pivot data set also changes...
    it often cuts off many lines... unless I refresh the data set used and tell it to use A1:M5000 of the Sheet 1
    I want to know how to tell it to do that for sheet1 and not care about the file name or online source

    we store the sheet online using excel online thru office 365/onedrive (a seperate excel sheet per office location)
    then each person in the department can "Color" the cells of the items they have completed...
    making it so the manager can see what has been done, and what still needs to be done....
    since sometimes gear comes in on an early truck, sometimes late, and everything has a deadline to go out depending on if its a cutsomer specified pickup or if its going on a freight truck, or UPS, or Fed Ex... we have to know what is done and what is not....
    this sheet makes it so we can see when an item is supposed to go out, and if its not done before its time to go out, we make a point to hurry up and find it and get it ready so it can make the deadline time

    because we store it online for "real time changes" across many computer stations
    in the morning, the manager will open the web location using onedrive online, and then you can select "Edit in Browser" for real time editing...but you cant update the pivot table online
    so instead, you can select to "Edit in Excel" which downloads the file and opens it locally on your computer....
    then when you are done, you hit save, and close it out and it automatically re-uploads and overwrites the file online so its ready for everybody to edit again.


    hopefully this clears ups what we are doing so you can understand what I need it to do as well...

    Like I said...
    I just need to know the VBA code to use to tell it to update the data set used without having to tell it a file name or an online location of the file

  6. #6
    Registered User
    Join Date
    04-29-2017
    Location
    Midwest
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    as an example....
    Macro says this

    ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
    PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "C:\Users\Scott\Desktop\[2017-03-03 QC Equipment Report In-Out.xls]QC Outbound!R1C1:R20000C13" _
    , Version:=xlPivotTableVersion10)
    Sheets("Pivot Inbound").Select
    ActiveSheet.PivotTables("PivotTable1").ChangePivotCache ActiveWorkbook. _
    PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
    "C:\Users\Scott\Desktop\[2017-03-03 QC Equipment Report In-Out.xls]QC Inbound!R1C1:R20000C12" _
    , Version:=xlPivotTableVersion10)

    can I get rid of the File location and replace it with some sort of "This workbook" command

  7. #7
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    If you are going to copy and paste data in, if you do it to excel tables, your pivot table will read exactly the data in the excel table regardless of how much data is imported. Then you can filter based on whatever the office ID is. All formulas running off the table also reference exactly the right amount of data.

  8. #8
    Registered User
    Join Date
    04-29-2017
    Location
    Midwest
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    Quote Originally Posted by dflak View Post
    If you are going to copy and paste data in, if you do it to excel tables, your pivot table will read exactly the data in the excel table regardless of how much data is imported. Then you can filter based on whatever the office ID is. All formulas running off the table also reference exactly the right amount of data.
    you arent quite understanding what is happening....
    Its not like you are thinking

    I just need a solution to Change the Pivot chart Data Set Just like in the VBA code I listed above... without having to tell it the file reference (the part that says "C:\Users\Scott\Desktop\[2017-03-03 QC Equipment Report In-Out.xls")

  9. #9
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    I do not understand. How do you expect the program to know what the new data source is if the user does not define it?

  10. #10
    Registered User
    Join Date
    04-29-2017
    Location
    Midwest
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    Quote Originally Posted by dflak View Post
    I do not understand. How do you expect the program to know what the new data source is if the user does not define it?

    It should not need to know a File...
    it only needs to know it should reference the "QC Outbound" Sheet in the workbook the pivot table is in......and not care about any other file/workbook....
    it shouldnt be looking for a source other than itself...nor do I want it looking for a source other than itself....

    I need VBA code that instead of saying a file location... it just says..."reference your own workbook only"

  11. #11
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    I think I might have it now. There is a QC Outbound Sheet in the workbook. There is data in this sheet and it does not matter how it gets there. Is this correct? So what you need is your pivot table built off this data.

    You can define the data as a named dynamic range and build the Pivot Table off of it. First create the pivot table. Then create the named dynamic range. Then change the source of the pivot table to the named range.

    The named dynamic range will act like an Excel table. As the user imports / copies & pastes or otherwise gets the data to the page, the dynamic range will accommodate it. No VBA is required.

  12. #12
    Registered User
    Join Date
    04-29-2017
    Location
    Midwest
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    Quote Originally Posted by dflak View Post
    I think I might have it now. There is a QC Outbound Sheet in the workbook. There is data in this sheet and it does not matter how it gets there. Is this correct? So what you need is your pivot table built off this data.

    You can define the data as a named dynamic range and build the Pivot Table off of it. First create the pivot table. Then create the named dynamic range. Then change the source of the pivot table to the named range.

    The named dynamic range will act like an Excel table. As the user imports / copies & pastes or otherwise gets the data to the page, the dynamic range will accommodate it. No VBA is required.



    This is Already what we are doing....
    Problem is not when we update the data, the problem is that we sort and delete rows out of the main data each day...(before the pivot table refresh)
    which in turn changes the dynamic range values of the pivot table...
    and we need to reset the dynamic range or the pivot table doesnt use all the data

  13. #13
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    I'm just not getting it. Maybe attaching a sample workbook will help.

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  14. #14
    Registered User
    Join Date
    04-29-2017
    Location
    Midwest
    MS-Off Ver
    Office 365
    Posts
    32

    Re: Code to Change Data Source for an online shared file, with out using the online link?

    Found somebody else who could help me out....
    This is what I was Looking for.....
    again... was looking for a "This Workbook" type of command....
    and this is it.


    ActiveSheet.PivotTables("PivotTable1").ChangePivotCache _
    ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="QCSheet!R1C1:R20000C12")
    ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh

+ 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. Replies: 1
    Last Post: 11-24-2016, 04:08 PM
  2. Replies: 0
    Last Post: 05-05-2014, 01:58 PM
  3. Replies: 0
    Last Post: 04-12-2013, 07:38 AM
  4. [SOLVED] Online excel shared
    By zhshqzyc in forum Excel General
    Replies: 8
    Last Post: 07-09-2012, 09:58 AM
  5. Importing from online data source to a master spreadsheet
    By ezzy85 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-23-2011, 01:41 PM
  6. Extracting Delimited Data from an Online Source
    By OlYeller21 in forum Excel General
    Replies: 0
    Last Post: 07-19-2006, 10:42 AM
  7. [SOLVED] How do I analyze data from a survey in excel:online source
    By LaReina in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-25-2005, 07:05 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