Excel/vsual basic
Expert: Tom Ogilvy - 11/7/2009
Questionwhich 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
AnswerNessie,
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