Results 1 to 4 of 4

Macro Looping

This is a discussion on Macro Looping within the Excel Questions forums, part of the Question Forums category; Is there a gerneral code for doing a procedure until a blank cell is reached. For example if i have ...

  1. #1
    Board Regular
    Join Date
    May 2002
    Posts
    60

    Default Macro Looping

    Is there a gerneral code for doing a procedure until a blank cell is reached.
    For example if i have a column a of data in Column A and I want to insert 2 blank rows between each data point until it reaches a blank cell.
    I have to do lots of this type of repetitive type of work and it would help greatly if I could use this code in different guises.

    kind regards

  2. #2
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    58,618

    Default

    Try this:

    Code:
    Sub Test()
        Dim x As Long
        Application.ScreenUpdating = False
        For x = Range("A65536").End(xlUp).Row To 1 Step -1
            Cells(x, 1).EntireRow.Resize(2).Insert
        Next x
        Application.ScreenUpdating = True
    End Sub

  3. #3
    Board Regular
    Join Date
    May 2002
    Posts
    60

    Default

    Thank you very much that works fine, I am right in saying the xlup part searches for the next occupied cell?

  4. #4
    MrExcel MVP
    Moderator
    Andrew Poulsom's Avatar
    Join Date
    Jul 2002
    Posts
    58,618

    Default

    Quote Originally Posted by matman
    Thank you very much that works fine, I am right in saying the xlup part searches for the next occupied cell?
    Range("A65536").End(xlUp)

    finds the last non-blank cell in column A. The code then loops backwards until it reaches row 1. The inserted rows are ignored because their row number is greater than the value of x.

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
  •  


DMCA.com