ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Get WorkSheet Name without a reason (https://www.excelbanter.com/excel-discussion-misc-queries/151794-get-worksheet-name-without-reason.html)

Dileep Chandran

Get WorkSheet Name without a reason
 
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


Mike H

Get WorkSheet Name without a reason
 
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

"Dileep Chandran" wrote:

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



Dileep Chandran

Get WorkSheet Name without a reason
 
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



All times are GMT +1. The time now is 07:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com