+ Reply to Thread
Results 1 to 3 of 3

problem with for next loop

  1. #1
    Registered User
    Join Date
    02-22-2014
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    2

    Unhappy problem with for next loop

    I am strugglig with the problem. Here is the image 1 after selecting one of element in listbox and then if I click delete material (commandbutton).
    1.png

    It has to delete the select material in sheet 2 and has to cut the element below and move to 1 row above as shown in figure 2.
    2.png

    At the same time it has to delete the entire respective column and remaining column has to be cut and place in column before in sheet 3 as shown in figure 3
    3.png
    For that I had wrote the program which is below
    Please Login or Register  to view this content.
    When I click the delete commandbutton5 the result is as shown in figure below
    In sheet2
    4.png

    In sheet 3
    5.png
    For loop is running only one time after that it got terminated. If I split the 1st for loop and execute it.it is running nice what I meant to do. If I combine another for loop or If I add msgbox at top it misbehaving.
    I tried with do while loop also it also doing same thing.

    Anyone can help me what is the actual mistake I am doing here and how to get ride of this problem or suggest me the easier method than this it will be helpful. I am beginner to vba programming ,so if your answer is simple and more explanatory manner means very helpful.Thanks in advance

    here is the sample file
    Last edited by ravi007008; 02-22-2014 at 11:59 AM. Reason: code tags added. Read forum rules

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,027

    Re: problem with for next loop

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between
    Please Login or Register  to view this content.
    tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)







    Picture:

    Hi and welcome to the forum

    Please do not upload a picture of your file...rather, upload a sample of your workbook, showing what data you are working with, a few samples of your expected outcome (manually entered is ok) and how you arrived at that. (Exclude sensitive info). Pictures are pretty much impossible to edit, and no-one wants to re-type your data for you. Also, not all members can upload picture files (Company firewalls, etc.)

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: problem with for next loop

    Do not use the same For variable as the To variable in a For statement. The For variable is changed as the loop progresses.
    Please Login or Register  to view this content.
    Also, in this case you could use the .Resize property instead of looping.

    This...
    Please Login or Register  to view this content.
    Does the same as this...
    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 02-22-2014 at 12:13 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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. Vlookup problem in a loop with cell property and variable cell problem (long title sry)
    By ExcelsiorLux in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2013, 10:38 AM
  2. [SOLVED] Loop inside a loop problem!
    By questionguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-22-2012, 12:54 PM
  3. Loop problem
    By pushkinpassey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-05-2012, 06:36 AM
  4. 'Loop Until' Problem
    By Iwasiw35 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-08-2011, 07:57 PM
  5. Problem adding charts using Do-Loop Until loop
    By Chris Bromley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2005, 09:06 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