AllExperts > Excel 
Search      
Excel
Volunteer
Answers to thousands of questions
 Home · More Excel Questions · Answer Library  · Encyclopedia ·
More Excel Answers
Question Library

Ask a question about Excel
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Tom Ogilvy
Expertise
Worked with the program for many years - provided assistance on MS Excel Newsgroups since 1997. Have received the Microsoft MVP award annually since 1999. I don't answer questions on using Excel in a browser Since I have no way to test this. Prefer not to answer charting questions. I consider myself to be particularly knowledgeable about using VBA internal to Excel but have no problems with formulas and pivot tables either.

Experience
Have Used Excel for 15 - 20 years. Answered in excess of 70,000 Excel related questions in MS Excel newsgroups. Unless obvious, please specify whether you want a worksheet function or macro/VBA solution.

Education/Credentials
BS General Engineering (concentration in Industrial Engineering) MS Operations Research Systems Analysis

 
   

You are here:  Experts > Computing/Technology > Microsoft Software > Excel > vsual basic

Excel - vsual basic


Expert: Tom Ogilvy - 11/7/2009

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


Ask a Question


 
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
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.