Converting a file to text

J

jhong

Hi Everyone,


I've got this very useful code from this forum, im running this code
to my excel file that has plenty of sheets with cost centers as sheet
names. My problem is each cost center starts with zero like 011888
when i run this code the macro will only get 11888 without the zero,
can you help me edit this code so it an get all the code as it is.
Thanks in advance!!

Dim NewSheet As Variant

Dim i As Integer


Set NewSheet = Sheets.Add(Type:=xlWorksheet)
For i = 1 To Sheets.Count
NewSheet.Cells(i, 1).Value = Sheets(i).Name
Next i
 
J

johnmanivong

Hi Everyone,

I've got this very useful code from this forum, im running this code
to my excel file that has plenty of sheets with cost centers as sheet
names. My problem is each cost center starts with zero like 011888
when i run this code the macro will only get 11888 without the zero,
can you help me edit this code so it an get all the code as it is.
Thanks in advance!!

Dim NewSheet As Variant

Dim i As Integer

Set NewSheet = Sheets.Add(Type:=xlWorksheet)
For i = 1 To Sheets.Count
    NewSheet.Cells(i, 1).Value = Sheets(i).Name
Next i

Try this
Dim NewSheet As Variant
Dim i As Integer
Set NewSheet = Sheets.Add(Type:=xlWorksheet)
For i = 1 To Sheets.Count
NewSheet.Cells(i, 1).NumberFormat = "@"
NewSheet.Cells(i, 1).Value = Sheets(i).Name
Next i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top