R
ryguy7272
I’m trying to run a (somewhat) simple procedure, but not getting the results
I am seeking. I have one sheet named “Control Sheet†and I am running the
macro from here. I am trying to insert a column into each of the other
sheets in the workbook (all sheets not named “Control Sheetâ€) and then get
the name of each sheet in cell A4 of each sheet. Sounds simple enough,
right. I played with the code below a little, but can’t get it to do what I
want it to do. I keep getting a message that says ‘Next Without For’, but I
thought I had the For and Next structured properly. Argh!! Any help would
be MUCH appreciated. TIA!
Sub ListNames()
Dim sh As Worksheet
Dim xs As Integer
For Each sh In ActiveWorkbook.Worksheets
If LCase(sh.Name) <> "Control Sheet" Then
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A3").Select
ActiveCell.FormulaR1C1 = "Tab Name"
For xs = 1 To Worksheets.Count
Worksheets(xs).Range("A4").Value = Worksheets(xs).Name
Next xs
Next sh
End If
Next
End Sub
I am seeking. I have one sheet named “Control Sheet†and I am running the
macro from here. I am trying to insert a column into each of the other
sheets in the workbook (all sheets not named “Control Sheetâ€) and then get
the name of each sheet in cell A4 of each sheet. Sounds simple enough,
right. I played with the code below a little, but can’t get it to do what I
want it to do. I keep getting a message that says ‘Next Without For’, but I
thought I had the For and Next structured properly. Argh!! Any help would
be MUCH appreciated. TIA!
Sub ListNames()
Dim sh As Worksheet
Dim xs As Integer
For Each sh In ActiveWorkbook.Worksheets
If LCase(sh.Name) <> "Control Sheet" Then
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A3").Select
ActiveCell.FormulaR1C1 = "Tab Name"
For xs = 1 To Worksheets.Count
Worksheets(xs).Range("A4").Value = Worksheets(xs).Name
Next xs
Next sh
End If
Next
End Sub