Date value
I bet that excel will see that "text" entry and parse it as a date.
If I wanted text, I'd use:
rng(1, 2) = "'January 1, " & TextBox1.Value '<-- with leading apostrophe
But I'd be more inclined to use:
with rng(1, 2)
.numberformat = "mm/dd/yyyy"
if isnumeric(me.textbox1.value) then
.value = dateserial(me.textbox1.value, 1, 1)
end if
end with
or for text:
with rng(1, 2)
.numberformat = "@"
if isnumeric(me.textbox1.value) then
.value = "January 1, " & me.textbox1.value
end if
end with
(Maybe even add some more validity checks, too.)
JLGWhiz wrote:
If you want it as a date:
rng(1, 2) = CDate("January 1, " & TextBox1.Value)
If you want it as text:
rng(1, 2) = "January 1, " & TextBox1.Value
"Patrick C. Simonds" wrote:
The user inputs a year Value to TextBox1. How can I amend the code below so
that January 1 of the year is inputted to into the cell?
Private Sub CommandButton1_Click()
Dim rng
Set rng = Cells(ActiveCell.Row, 1)
rng(1, 2).Value = TextBox1.Value
Module2.Rename_Worksheets
Unload Year
End Sub
--
Dave Peterson
|