+ Reply to Thread
Results 1 to 5 of 5

For Loop not completing

  1. #1
    Registered User
    Join Date
    09-01-2011
    Location
    Delhi, India
    MS-Off Ver
    Excel 2010
    Posts
    3

    For Loop not completing

    Hi All,

    I am relatively new to macro and I was trying to use For loop in my code. It appears the loop is not running till end. My excel has some date columns but there are few columns where there is a gap in date between two consecutive columns. So what I was trying to do is to insert a column whereever there is a gap. and fill out the column header with the appropiate coulmn value. Below is the code that I wrote:

    Please Login or Register  to view this content.
    on executing the code the value that I am getting for i is 40 and of last col as 52 (lastcol is the last column of the datarange).

    Will deeply apreciate if anyone can guide me on the mistake that I am making.

    Thanks
    -Som
    Last edited by somnath.deb; 09-01-2011 at 11:52 PM.

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: For Loop not completing

    Probably because you are incrementing lastcol in the inner loop. Why are you doing that?

  3. #3
    Registered User
    Join Date
    09-01-2011
    Location
    Delhi, India
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: For Loop not completing

    That is because when I am inserting a new column it is pushing the last column of the data range one column towards right so need to increment lastcol by one

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: For Loop not completing

    Hi somnath.deb

    When adding/deleting columns or rows iterate through them backward (rows from the bottom up, columns from right to left).
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    09-01-2011
    Location
    Delhi, India
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: For Loop not completing

    Quote Originally Posted by jaslake View Post
    Hi somnath.deb

    When adding/deleting columns or rows iterate through them backward (rows from the bottom up, columns from right to left).
    Please Login or Register  to view this content.
    Thank you so much jaslake, it solved my issue.. truly appreciate your help, as suggested by you I marked the thread as solved !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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