Consulting

Results 1 to 10 of 10

Thread: Solved: Looping around a userform textbox

  1. #1
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location

    Solved: Looping around a userform textbox

    Hi all

    I have a userform txtbox called TxtLineRef, whats the best way to insert "A "on the first loop then B Then C etc upto Z
    I have a dynamic array on sheet 3 called Lineref, can i call the index of the array or would it be best to loop from 1 to 26 inserting the letters on each loop.
    Can do with a combo box but didn't want the user to have access to this field.

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    What loop?
    Insert the characters where?
    What is in Lineref and what does that have to do with the text box?

    Why could a user access a combobox but not a text box?

    If you attach a small, representative workbook that illustrates your situation, it would help folks understand what you are after.

  3. #3
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    hi Rob.

    you can adopt this

    [VBA]
    Sub incr_lett()

    For i = 65 To 90
    msg = msg & Chr(i) & vbCr
    Next

    MsgBox msg

    End Sub
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  4. #4
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Mike
    Have attached a workbook, its the Line Ref in RED trying to update ie
    Start at line A when the details are added, if the user wants to add another clm then this field would get updated to B automatically.

    Mancubus

    That would work, thanks for that never thought to use Chr ()

    Rob
    Attached Files Attached Files

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    You need to set the .Locked property of the text box to False. Then a line like this will fill in the proper value
    [VBA]With Range("CorpIdBranch")
    Me.TxtClmNo.Text = CStr(.Offset(.Rows.Count, 0).End(xlUp).Offset(1, 3).Value)
    End With
    [/VBA]

  6. #6
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi Mike

    Have tried the code it gives me "F" all the time. It should start at A , then when the user hits the Add button then the line should increment to "B" and so on.
    There are only 5 branches there in the test but there could be 100.


    Rob

  7. #7
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Which line do you want returned?
    That routine returns the letter from the row after the last filled row.

    Are you looking for somethign like

    Static IncrimentNumber As Long
    
    If IncrimentNumber < 64 Then IncrimentNumber = 64
    IncrimentNumber = IncrimentNumber + 1
    TextBox1.Text = Chr(IncrimentNumber)

  8. #8
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi Mike

    Thanks that works all ok, where in your opinion would be the correct place to slot that code in ie when that textbox gets focus or before update , afterupdate ?

    Rob

  9. #9
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    I don't understand what you are doing so I couldn't answer when this part of it should be done.

  10. #10
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Thanks to you both most appreciated , i can work with both of these options.

    Regards
    Rob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •