PDA

View Full Version : [SOLVED] VBA Code to stop loop if cell / range is blank



Steve Belsch
12-10-2019, 01:05 PM
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

Steve Belsch
12-10-2019, 01:40 PM
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

Paul_Hossler
12-10-2019, 01:43 PM
If Len (cell.value) = 0 then Exit Sub


or


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