Excel/vsual basic

Advertisement


Question
which of the following would place the insertion point in the first position of a text box named txtItem?
txtItem.SelLength=0
txtItem.SelStart=0
txtItem.Text=0
txtItem.Text=1
thanks

Answer
Nessie,

I created a userform and with Textbox1 and a commandbutton.

I then put this code in the commandbutton to illustrate


Private Sub CommandButton1_Click()

TextBox1.Value = "The dog is big and fat"
MsgBox TextBox1.SelStart & " " & TextBox1.SelLength
TextBox1.SelStart = 1
TextBox1.SelLength = 0
MsgBox TextBox1.SelStart & " " & TextBox1.SelLength


End Sub


so after it enters the text, the insertion point is a 22.

after the SelStart and SelLength commands are issued, the insertion point is a position 1.

The reason I am providing this is that I am not sure what you are trying to do.  If the textbox doesn't have any text in it, the insertion point is in the first position (0).  Regardless of where the insertion point is located, if the Textbox doesn't have the focus, you won't see the cursor.

If the textbox has text in it and it doesn't have then focus, then if you click in the box or tab to it, that will change the insertion point.  

In general,

txtItem.Text=0
txtItem.Text=1
will put 0 and 1 in the textbox respectively

txtItem.SelLength=0  would allow no text to be selected (just a cursor in the cell)
txtItem.SelStart=0  would place the insertion point in the center.

--
Regards,
Tom Ogilvy

About Excel
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

Excel

All Answers


Answers by Expert:


Ask Experts

Volunteer


Tom Ogilvy

Expertise

Selected as an Excel MVP by Microsoft since 1999. Answering Excel questions in Allexperts since its inception in 2001. Able to answer questions on almost all aspects of Excel's internal capabilities. If seeking a VBA solution, please specify that in your question itself so I give you the answer you want. [Excel has weak protection - if you are distributing an application, I don't answer questions on how to protect your project from your users.]

Experience

Extensive experience.

Education/Credentials
Master of Science (MS) degree Operations Research (ORSA)

Awards and Honors
Microsoft MVP in Excel.

©2012 About.com, a part of The New York Times Company. All rights reserved.