+ Reply to Thread
Results 1 to 2 of 2

VBA - Loop not working, where have I gone wrong???

  1. #1
    Registered User
    Join Date
    02-14-2020
    Location
    England
    MS-Off Ver
    2010
    Posts
    1

    Question VBA - Loop not working, where have I gone wrong???

    Hi everyone, my first post (please be gentle!) (Edit - Managed to solve it, in a moment of madness I listened to a colleague and put an "on error resume next" in - I'll not make that mistake again! Apologies for missing the code tags, I'll be better prepared next time!)

    I've put together a userform which copies the details entered to another workbook (it opens that workbook, copies the data in, saves and closes it). This and the associated macro all work fine, but I wanted to add some additional protection in because the external file will be updated by multiple users.

    I found some code and managed to get a loop working to open the file, and try again if it was read only (code below);

    Please Login or Register  to view this content.
    This test sub does what I want it to (there's probably a better way of doing it, but I'm not particularly advanced with VBA). If the file opens and is read only, it brings up the message box and then tries again when the user clicks OK. It keeps doing this until the file is no longer read only.

    My problem is when I incorporate that code in to the macro that does everything else, it doesn't behave as I expect it to. It recognises that the external file is read only, but on clicking OK it doesn't loop, it just closes the workbook from which the macro was run. I'm hoping that it's something simple that I'm missing causing this behaviour, so I've put the other macro below.

    If anyone can point out where I've gone wrong I'd appreciate it. Thanks in advance

    Please Login or Register  to view this content.
    Last edited by Wadders; 10-02-2020 at 03:52 AM.

  2. #2
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,304

    Re: VBA - Loop not working, where have I gone wrong???

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). 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.

+ 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. [SOLVED] What's wrong with Range in this For loop
    By pumper in forum Excel Programming / VBA / Macros
    Replies: 21
    Last Post: 08-30-2020, 06:25 PM
  2. [SOLVED] What's wrong with this loop?
    By DMA in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-15-2017, 05:18 AM
  3. [SOLVED] Whats wrong with my loop
    By dlow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2015, 03:45 PM
  4. [SOLVED] Whats wrong with this loop
    By rpinxt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2014, 07:05 AM
  5. What is wrong with this for loop?
    By kmakjop in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-17-2014, 02:31 PM
  6. If Loop Wrong Usage?
    By coconutmango in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2011, 08:11 PM
  7. What's wrong with my loop ?
    By Grek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-13-2006, 02:23 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