Get WorkSheet Name without a reason

  • Thread starter Thread starter Dileep Chandran
  • Start date Start date
D

Dileep Chandran

Hello Masters,

I have a macro which will get the list of worksheet names. It works
fine untill I add some more worksheets and run it again.

The craziest thing is that if I go to the code and simply add a space
of delete a space, or just cut and paste the code, it works fine.

Any idea what could be wrong??

Thanks in advance for any help

-DC
 
It could only be a guess without seeing the code but here's some that does
wotk that you could maybe adapt:-

Sub getnames()
x = 1
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Sheets("Sheet1").Cells(x, 1).Value = ws.Name
x = x + 1
Next ws
End Sub

Mike
 
Hi Mike,

Thanks for your reply. I have the same code. But it still fails to
work without opening the code and refresh.

Heres my code:

Sub WsNames()

Dim i As Long
Dim Sh As Worksheet
i = 6


For Each Sh In ActiveWorkbook.Sheets

Range("B" & i) = Sh.Name
Range("A" & i) = Sh.CodeName
i = i + 1

Next

End Sub

Any idea to rectify?

Thanks

DC
 
Back
Top