Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Add Text to Range in Excel

Status
Not open for further replies.

YerMom

Programmer
Oct 3, 2006
127
US
Hi,
I have a spreadsheet and I need to add text to a cell.

The coordinates (row and column) that I want to use for the cell are defined by two Integer variables:
Code:
Dim vCol As Integer
Dim vRow As Integer

I've seen entries in the online help that seem to indicate the following might be possible. (I can't find help entries that seem to address my problem.)
Code:
Application.Workbooks(1).ActiveSheet.Range.Cells(vRow, vCol).Text = "my text"

But when run the macro, I get the following error:
Code:
Wrong number of arguments or invalid property assignment

I'm not sure how to define the range so I can set the text.
Can anyone help?
Thanks...
 
Hi,

"add text to a cell"

Does that mean that your may already have text in the cell and you want to append other text or you just want to assign text to a cell?
Code:
'vRow and vCol bust BOTH have valid values
ActiveSheet.Cells(vRow, vCol).Value = "my text"
There is no TEXT property of a range.



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Actually, there is a .Text property of a Range, but it's read only.

What you want is to change the .Value property of the Range.

From Help:
This example illustrates the difference between the Text and Value properties of cells that contain formatted numbers.
Code:
Set c = Worksheets("Sheet1").Range("B14")
c.Value = 1198.3
c.NumberFormat = "$#,##0_);($#,##0)"
MsgBox c.Value
MsgBox c.Text

 
I should have been more specific that you cannot use the TEXT property to assign values as the OP wants to do.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Thanks Skip and DaveInIowa. I used the value property and it worked fine. For clarification, I was trying to add text to a cell without any text previously in it.

Skip: Enjoy your nuance! LOL
 
Adding to, indicates taking something and appending to it. You are referring to assigning a value, rather than adding a value.

Assigning
a = 1
b = "one"

Adding
a = a + 1
b = b & "one"

Just a small nuance.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip,

Yes, I see how I caused confusion. Sorry about the mxixup, and thanks again for your help -- I appreciate the time you took.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top