+ Reply to Thread
Results 1 to 5 of 5

Macro to refresh connections and add formulas

  1. #1
    Registered User
    Join Date
    06-14-2017
    Location
    London, England
    MS-Off Ver
    Professional Plus 2016
    Posts
    7

    Macro to refresh connections and add formulas

    I have an Excel file with a number of connections which can be refreshed. I am trying to build the following macro to a) refresh all connections throughout the workbook, b) add a value to two specific cells on one worksheet, then c) add two formulas which should be applied as far as the last row of data (once the connections have been refreshed):

    Please Login or Register  to view this content.
    This returns an error as follows:

    ErrorMessage.PNG

    If I choose 'End', the connections continue to refresh and the values are inserted into cells N1 and O1 but the formulas are not added.

    Any ideas? I'm pretty new to VBA so apologies if I've made some very basic errors!
    Last edited by AliGW; 01-02-2018 at 05:24 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Macro to refresh connections and add formulas

    Oops, please use [CODE][/CODE] tags when posting code. It makes it easier to read and long code won't clutter up the page

    You have two subs there with the same name, they need to have unique names.

    In the second instance of GetData() there is a variable called LastRow which hasn't been declared or set. See here about declaring variables.
    http://www.cpearson.com/Excel/DeclaringVariables.aspx
    It's almost always best to turn on the setting that puts "Option Explicit" at the top of your modules so that you can't use a variable that hasn't been declared.

    To get your LastRow number see here: http://www.cpearson.com/Excel/LastCell.aspx


    I hope that helps
    Design everything to be as simple as possible, but no simpler.

  3. #3
    Registered User
    Join Date
    06-14-2017
    Location
    London, England
    MS-Off Ver
    Professional Plus 2016
    Posts
    7

    Re: Macro to refresh connections and add formulas

    Thank you Stormin' - incredibly helpful. Very useful links too

    And thanks for the
    Please Login or Register  to view this content.
    advice.

  4. #4
    Valued Forum Contributor
    Join Date
    03-16-2017
    Location
    UK
    MS-Off Ver
    2016
    Posts
    371

    Re: Macro to refresh connections and add formulas

    Happy to help
    If that takes care of your original question, please select Thread Tools from the menu link above to mark this thread as SOLVED.
    To say thanks to the user(s) who contributed towards the solution, you can use the "Add Reputation" button on their helpful post(s).
    Thanks!

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Macro to refresh connections and add formulas

    Code tags added and thread marked as solved - please try to follow this forum's etiquette in future threads. Thanks!
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Refresh all data connections, save and close
    By izk630 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-27-2016, 10:58 AM
  2. Refresh All vs. Refresh All Data Connections
    By TK92 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-22-2016, 09:14 AM
  3. Refresh data connections with delay via macro
    By Jimmyjazz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2013, 01:57 AM
  4. Refresh Specific Sheets/ Connections
    By hyp3rbola in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-31-2013, 04:50 PM
  5. Safe way to refresh many connections without saving the password?
    By bristly in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-24-2013, 06:29 AM
  6. [SOLVED] Data Tab -- Refresh All data Connections on multiple sheets - Need a macro
    By aetedford in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2013, 06:40 PM
  7. Macro to Refresh data Connections in each Tab of an excel
    By pnandak in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2012, 04:47 AM

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