+ Reply to Thread
Results 1 to 18 of 18

Edit VBA Userform code to run if only 1 entry that matches criteria

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Edit VBA Userform code to run if only 1 entry that matches criteria

    Thanks..what do you mean by the loop?

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Edit VBA Userform code to run if only 1 entry that matches criteria

    Check the below code for details to know where to add the suggested code...

    Private Sub UserForm_Initialize()
    Dim rRng As Range, r As Range, rSortCr As String
    
    Set rRng = Sheet2.Range("a2:a5567")
    rSortCr = UCase(ActiveCell.Value)
    
    For Each r In rRng
        If InStr(UCase(r), rSortCr) Then Me.ListBox1.AddItem r.Value
    Next r
    
    If Me.ListBox1.ListCount = 1 Then
        Me.ListBox1.ListIndex = 0
        Selection.Value = Me.ListBox1.Value
    End If
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Contributor
    Join Date
    03-06-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2010
    Posts
    352

    Re: Edit VBA Userform code to run if only 1 entry that matches criteria

    Thanks that works - how do I unload the userform after it's chosen the word for me?

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Edit VBA Userform code to run if only 1 entry that matches criteria

    Just close it by clicking the X mark.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Userform multipage control exit events code execution not completed before next user entry
    By jane serky in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-10-2013, 04:39 AM
  2. Populating VBA userform and Fetch previously entered data edit and make new entry
    By vijaynadiad in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-07-2013, 11:59 AM
  3. VBA Code to Search/Edit Data Populated by Userform
    By pjohnson9 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-06-2011, 04:25 PM
  4. Return last entry in column that matches criteria
    By tomlancaster in forum Excel General
    Replies: 4
    Last Post: 01-22-2010, 10:27 AM
  5. Edit code to add extra criteria
    By duugg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2008, 11:34 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1