Placing TextBox text in cell

  • Thread starter Patrick C. Simonds
  • Start date
P

Patrick C. Simonds

Can anyone tell me why I get an error (Object required) on the line:

ActiveCell.Text = TextBox2.Text

The code is run from a UserForm and is intended to replace the contents of
the active cell with the text in TextBox2



Private Sub CommandButton7_Click()
Dim rng As Range

Dim aSht As Worksheet
Dim aCel As Range
Set aSht = ActiveSheet
Set aCel = ActiveCell
Application.ScreenUpdating = False

ThisWorkbook.Sheets("paratransit names").Activate
Cells.Find(What:=TextBox1.Text, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False).Activate

ActiveCell.ClearContents
ActiveCell.Text = TextBox2.Text


aSht.Activate
aCel.Select

Application.ScreenUpdating = True
End Sub
 
R

Rick Rothstein \(MVP - VB\)

Use ActiveCell.Value instead of ActiveCell.Text... the Text property for a
Range object is Read Only.

Rick
 
G

Gary''s Student

Anything like:

Sub fhakf()
ActiveCell.Text = "xxx"
End Sub

will fail since Text is read-only for Ranges.


Use ActiveCell.Value
 

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