Consulting

Results 1 to 3 of 3

Thread: VBA Code to stop loop if cell / range is blank

  1. #1

    VBA Code to stop loop if cell / range is blank

    Hi VBA Experts,

    I am looking for some help on a VBA code that is meant to rename worksheet tabs within a work book referencing a list in another worksheet. I want the loop to stop if a cell in the referenced range is blank. I have attached an example workbook with the module.

    I am sure it is a simple condition but can't think of how to do this. Any ideas?

    Thanks.
    Steve
    Attached Files Attached Files

  2. #2
    I figured out a way. Here is the code.

    Sub RenameSheets()


    Dim c As Range
    Dim J As Integer




    J = 8
    For Each c In Range("E8:E153")


    If Cells(J, 5) = "" Then
    Exit Sub
    End If


    J = J + 1

    If Sheets(J).Name = "List" Then J = J + 1
    Sheets(J).Name = c.Text

    Next c




    End Sub

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    If Len (cell.value) = 0 then Exit Sub


    or


    If Len (cell.value) = 0 then Exit For ( or Loop)
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •