+ Reply to Thread
Results 1 to 6 of 6

Writing to cell stops for loop

  1. #1
    Registered User
    Join Date
    04-18-2016
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    3

    Writing to cell stops for loop

    Hi,

    I want to write all the selected values in a listbox in a range of cells. Every time listbox.selection(x) = true, I increase the offset of the range in the worksheet with the variable i.
    It works perfect if I don't write to the worksheet. For exemple if I don't change the value but instead select the cell.
    But when I change the value of the cell in the worksheet the variable i doen't count anymore.

    When I select 5 things for example cell A1 is the first selected thing in the listbox, the other cells stay empty.
    Please Login or Register  to view this content.
    The following code works perfect, when I select 5 things, cell A6 is selected.
    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Writing to cell stops for loop

    Do you definitely have multi-select enabled in your listbox?

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Writing to cell stops for loop

    It should be working. Submit you workbook because something else is probably going on that you cannot see.
    If you are happy with my response please click the * in the lower left of my post.

  4. #4
    Registered User
    Join Date
    04-18-2016
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    3

    Re: Writing to cell stops for loop

    Submitting the workbook wouldn't be possible because of the size so I made a new workbook with only this function. The new workbook worked perfect. The only difference was that in the new workbook the data in the rowsource were not calculated. In the original workbook, the rowsourcedata was calculated. It was collected out of another active workbook with =INDIRECT("'[workbook2.xlsx]"&$C$2&"'!"&C$3&$A5). When I changed this in noncalculated data, the VB code worked. So I had the impression that the automated calculation interfered. When I disabled automatic calculation the VB function worked perfect.
    I added two lines in my code to stop the calculation before the loop and turn the calculation back on after the loop. This seems to work but I still have no clue why the loop interfered with the calculation.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Writing to cell stops for loop

    Could putting the values from the listbox on the sheet be triggering calculation and therefore triggering the repopulation of the listbox and interrupting the code by triggering some other event?

    You could check if that was happening by stepping through the code with F8.
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    04-18-2016
    Location
    Belgium
    MS-Off Ver
    2016
    Posts
    3

    Re: Writing to cell stops for loop

    Not that I'm aware of. Repopulation doesn't happen otherwise the selected values should be unselected.
    Now I have created another function that fills the same range and this function works without stopping the calculation.

+ 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] Do While ....Loop Never Stops
    By jadown in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-17-2013, 09:29 AM
  2. VBA - Loop stops too soon
    By DavidBW in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2013, 06:42 AM
  3. loop that stops when certain value is obtained
    By ukhan12 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-07-2013, 10:41 PM
  4. [SOLVED] A Loop does not loop throught. It stops after two cells.
    By AB33 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-14-2012, 01:14 PM
  5. Code Stops in a loop?
    By playtowinpb@msn.com in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2011, 01:57 PM
  6. Subroutine loop -- Stops after first, active sheet
    By za20001 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2011, 02:51 PM
  7. For Loop STOPS at Random Iteration!
    By wjoc1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2007, 09:58 AM
  8. [SOLVED] Formula in loop stops working
    By Jim73 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2005, 12:06 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