+ Reply to Thread
Results 1 to 5 of 5

Retreiving Data from workbook, but rows can be added or removed.

  1. #1
    Registered User
    Join Date
    04-12-2019
    Location
    Manchester
    MS-Off Ver
    2016
    Posts
    20

    Retreiving Data from workbook, but rows can be added or removed.

    Hi,

    I've written a macro that pulls data from certain cells from a workbook.

    The only issue is that within this workbook someone could select an option and this would insert a row.

    So my code would be one line out.

    I 've handled this with an ELSEIF function as I anticipate that this option could realistically be selected 5 times, this has worked thus far.

    But now I am trying to pull a cell that could be affected if someone has manually inserted a row, therefore adding a lot more complexity.

    Any ideas?

    Ps I can't edit the workbook from where I pull the data this is locked.

    Thanks
    Christian

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Retreiving Data from workbook, but rows can be added or removed.

    You have Excel 2016. Use PowerQuery (called Get & Transform) to pull in the data. It will be dynamic. You can then use GUI or M query language to transform data as you see fit.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Retreiving Data from workbook, but rows can be added or removed.

    Make your range dynamic and use a variable to hold the range parmeters. Use the variable throughout the code instead of the hard coded range parameters.
    Please Login or Register  to view this content.
    Then it will automatically adjust the range regardless of the adding or deletion of rows.
    Last edited by JLGWhiz; 04-17-2019 at 02:05 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  4. #4
    Registered User
    Join Date
    04-12-2019
    Location
    Manchester
    MS-Off Ver
    2016
    Posts
    20

    Re: Retreiving Data from workbook, but rows can be added or removed.

    Hi JLGWhiz,

    Although I am not sure this would work for my problem. See code below

    Please Login or Register  to view this content.
    As you can see the option that adds a row fortunately I can take values from a cell to run an if function. If it's empty it means that, that particular row hasn't been added.

    Where I am struggling is that in another area a row can be added randomly and no cell would have an extra value. Does that make sense?

    Thanks
    Christian

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Retreiving Data from workbook, but rows can be added or removed.

    The issue is different than I first envisioned. What you are apparently trying to do is make the code idiot proof. That could take a lot of If...Then statements to cover all aspects of what a user might do. I think it might be easier to make sure your users understand the limitations. You can put a condition in the code for the unexpected blank row by having a message box pop up to tell the user that no data was found and which workbook the problem occurred in so they can take remedial action. then allow the code to continue for any remaining workbooks. Flagging the anomally is easier than trying ot out guess the user.

    An alternative would be to make sure the source workbook has data in the appropriate range before it is saved.
    Last edited by JLGWhiz; 04-18-2019 at 09:23 AM.

+ 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. Macro to check new employees added/removed btw two sheets
    By jw01 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2017, 01:21 PM
  2. [SOLVED] Using ROW command to automatically edit the numbers when a row gets added or removed
    By The excel apprentice in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 03-18-2016, 09:28 AM
  3. [SOLVED] VBA or Macro to Check if Information has been Added, Removed, or Stayed the same.
    By Lowen in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-19-2015, 03:10 PM
  4. Replies: 1
    Last Post: 07-15-2015, 06:40 PM
  5. Find removed and added entries comparing two worksheets
    By wintheranders in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-05-2013, 05:50 AM
  6. Comparison for monthly reports.... accounts added and removed
    By SpottedTApps in forum Excel General
    Replies: 1
    Last Post: 03-08-2012, 03:59 AM
  7. Replies: 1
    Last Post: 07-12-2006, 01:40 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