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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cursor Position within a Cell 1

Status
Not open for further replies.

mrsnrub

Programmer
Mar 6, 2002
147
AU
Hello all,
I have a macro in an Excel spreadsheet that automatically inserts some required text into a cell that falls within a particular range when the user double-clicks on the cell. That part of the code is working well, but I want to allow the user to continue adding more text to the end of this automatically inserted text.
At the moment, the flashing cursor is positioned for editing wherever the double click was performed over the cell. I want to make sure that the cursor is positioned after the last character in my automatically inserted text, ready for the user to continue typing.

Is this possible?

Many thanks in advance.
 
I think you can avoid controlling cursor position using this:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim MyStandardText As String, Inp As String
MyStandardText = "Test blah blah blah"
Inp = InputBox("This text will be write:" & vbCrLf & MyStandardText, _
                                                    "Writing in a cell")
  If Inp = "" Then
    Target.Value = MyStandardText  
  Else
    Target.Value = MyStandardText & " " & Inp
  End If
End Sub

Fane Duru
 
Thank you for this solution FaneDuru.

Your solution will avoid me having to position the cursor myself (and this particular user will probably like having a form to fill in!)

Many thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top