ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   New Users to Excel (https://www.excelbanter.com/new-users-excel/)
-   -   How do you change the data type of a cell using VBA? (https://www.excelbanter.com/new-users-excel/172928-how-do-you-change-data-type-cell-using-vba.html)

justme0010

How do you change the data type of a cell using VBA?
 

For instance, with VBA I am trying to place "February 2007" in a cell
but it keeps showing up as Feb-07. I want it to show up as literal
text.




--
justme0010

Gary''s Student

How do you change the data type of a cell using VBA?
 
Sub text_it()
Range("A1").Value = Chr(39) & "February 2007"
End Sub

--
Gary''s Student - gsnu2007c

Dave Peterson

How do you change the data type of a cell using VBA?
 
You could keep the value a date and just format the cell the way you like:

with activecell
.numberformat = "mmmm yyyy"
.value = dateserial(2007,2,1)
end with

You could also format the cell as text first:

with activecell
.numberformat = "@" 'text
.value = "February 2007"
end with

or this variation of Gary's Student's response:

with activecell
.numberformat = "General"
.value = "'February 2007"
end with



justme0010 wrote:

For instance, with VBA I am trying to place "February 2007" in a cell
but it keeps showing up as Feb-07. I want it to show up as literal
text.

--
justme0010


--

Dave Peterson


All times are GMT +1. The time now is 09:21 PM.

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