Re-write this code to skip rows

klarowe

Active Member
Joined
Mar 28, 2011
Messages
389
Right now I have this code for automatically numbering my index according to what sheets are visible/not visible:
Code:
Sub IndexNumber()
    Dim lx As Long
    Dim sIndex As String
    Dim sIndexStartRange As String
    Dim lVisibleCount As Long
    sIndex = "Index"
    sIndexStartRange = "A7"
    Worksheets(sIndex).Range("A7:A100").Cells.ClearContents
    With Worksheets(sIndex).Range("A7")
        For lx = 1 To Worksheets.Count
            Select Case Worksheets(lx).Name
            Case Else
                If Worksheets(lx).Visible = True Then
                    lVisibleCount = lVisibleCount + 1
                End If
                If Worksheets(lx).Visible = True Then .Offset(lx - 1, 0) = lVisibleCount
            End Select
        Next
    End With
End Sub

And the index currently looks like this:
Indexold.jpg


What I want to do is re-write the above code to allow extra spacing between the rows starting at row 12 to allow room for a description to be added (will be set up to automatically be added according to the A3 value of each sheet).

Here is how I would like the end result to appear... with the index numbering still being automatic:
Indexnew.jpg


Thanks again in advance.... you guys are lifesavers!!!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I haven't tried your posted code but if you start out with your data looking like your first screenshot, then run this code on it, you'll end up with your data looking like your second screenshot.
Code:
Sub AddRowsDemo()
Dim LstRw As Long, NewRw As Long
LstRw = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For NewRw = LstRw To 14 Step -1
  Rows(NewRw).EntireRow.Insert
  Cells((NewRw), "A").Value = "Description"
Next
Application.ScreenUpdating = True
End Sub

Hope it helps.
 
Upvote 0
No, that doesn't quite work b/c it doesn't really solve the index numbering issue.
Its not a big deal, I've developed a work around for it (re-formated the columns and added an extra description column to the side) for now which should work fine.
Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,820
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top