+ Reply to Thread
Results 1 to 4 of 4

Is there a way to put the row number on a value found on a worksheet into a textbox?

Hybrid View

  1. #1
    Registered User
    Join Date
    06-17-2021
    Location
    Washington, USA
    MS-Off Ver
    Current
    Posts
    19

    Is there a way to put the row number on a value found on a worksheet into a textbox?

    So let's say I have a worksheet with a column filled with phone numbers. I have a userform with a text box that I will be typing in a phone number into, and I want a different text box to reflect the number of the row that the phone number is found in on the worksheet.

    I've looked around, but all the codes I've seen people write are very specific to their needs and much different from another.

  2. #2
    Registered User
    Join Date
    06-17-2021
    Location
    Washington, USA
    MS-Off Ver
    Current
    Posts
    19

    Re: Is there a way to put the row number on a value found on a worksheet into a textbox?

    Found a solution that worked!


     Dim row As Range
    Set row = ws.Cells.Find(What:=MAINNUMTEXTBOX.Value, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    ROWNUMBERTEXTBOX.Value = row.row

  3. #3
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,543

    Re: Is there a way to put the row number on a value found on a worksheet into a textbox?

    Yet another solution.

    Code in the form module:
    Option Explicit
    
    Dim vPhones         As Variant
    
    
    Private Sub txtPhone_Change()
        Dim v           As Variant
    
        v = Application.Match(Me.txtPhone.Value, vPhones, 0)
    
        If IsError(v) Then
            Me.lblDataRow.Caption = vbNullString
            Me.lblSheetRow.Caption = vbNullString
        Else
            Me.lblDataRow.Caption = v
            Me.lblSheetRow.Caption = v + 3
        End If
    
    End Sub
    
    
    Private Sub UserForm_Initialize()
        With Me.lblDataRow
            .Caption = vbNullString
            .TextAlign = fmTextAlignCenter
            .Font.Bold = True
        End With
    
        With Me.lblSheetRow
            .Caption = vbNullString
            .TextAlign = fmTextAlignCenter
            .Font.Bold = True
        End With
    
        Me.txtPhone.Value = vbNullString
    
        With ActiveSheet.Range("A3").CurrentRegion
            vPhones = .Offset(1).Resize(.Rows.Count - 1).Columns(1).Cells.Value
        End With
    End Sub
    Artik
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,707

    Re: Is there a way to put the row number on a value found on a worksheet into a textbox?

    Is the value you're looking for part of a longer string or a value by itself?
    Do a search in the difference having "xlWhole" and "xlPart" in the Find Function.
    The inherent weakness of the liberal society: a too rosy view of humanity.

+ 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] Highlight listbox value if textbox value found in column 2
    By JamesT1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2022, 05:26 PM
  2. Textbox VBA code if values not found
    By Eon25 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-13-2016, 12:40 AM
  3. Replies: 4
    Last Post: 01-29-2014, 05:53 AM
  4. VBA - Macro Code to copy textbox text to another worksheet textbox
    By nitram lowm in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2013, 08:39 AM
  5. Macro to copy textbox data to a duplicate textbox in another worksheet
    By nitram lowm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-02-2013, 06:10 AM
  6. Userform to search textbox value to place other textbox values in worksheet
    By mattyh555 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-19-2012, 11:38 AM
  7. Find Text from textBox then past what is found on sheet1
    By Mark Cover in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2005, 12:05 PM

Tags for this Thread

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