Problem format when getting the name of an excell sheet in VBA

0

As ridiculous as it seems I have a problem when it comes to getting the name of a Excel sheet because it is written to me in date format. The sheet has name JUL02 and I want to get exactly the literal "JUL02", however, when reading the name of the sheet and writing it in a cell, what you type is 02-Jul, as if it was a date. As simple as:

resNam = Workbook.Worksheets(l).Name  
Workbook.Worksheets.Cells(a, b) = resNam

I've already tried with CStr both CStr(Workbook.Worksheets(l).Name) as CStr(resNam) , but still putting the same. Any help or approach is appreciated.

    
asked by Tino Fernández 02.04.2018 в 14:13
source

1 answer

1

Basically you get the name of your sheet correctly, what you need to do is format the column where you store the data, even if you convert String type your variable if the format of the column is different it will not go to work .. With this code works perfectly.

resNam = ActiveSheet.Name
ActiveSheet.Cells(1,4).Value = resNam
ActiveSheet.Cells(1,4).NumberFormat = "@"

in your case you could add this line:

Workbook.Worksheets.Cells(a, b).NumberFormat = "@"

I hope it serves you, I am ordering.

    
answered by 02.04.2018 / 17:45
source