+ Reply to Thread
Results 1 to 4 of 4

Search String then add data next to it.

Hybrid View

  1. #1
    Registered User
    Join Date
    06-06-2016
    Location
    London
    MS-Off Ver
    2010
    Posts
    50

    Search String then add data next to it.

    Hello,

    I was wondering if anyone can help?

    I have some data which will populate column A in worksheet "Data".

    I also have a userform where I want the user to enter a string that will search column A and if that string exist will enter a number/count in the next available space next to that string. (from columns B onwards)

    I've added an attachment excel as an example.

    Thanks for any help!

    JP
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,117

    Re: Search String then add data next to it.

    Is this what you mean?

    Private Sub cmdSave_Click()
    Dim i&, c&, r&
    Dim f As Range, fa
    Dim sMsg$
    If txtSearch.Text = "" Or Not IsNumeric(txtCount.Text) Then
        sMsg = "Not enough info."
    Else
        With Sheet1
                Set f = .Range("A:A").Find(what:=txtSearch.Text, lookat:=xlWhole)
                If Not f Is Nothing Then
                    fa = f.Address
                    r = .Range(f.Address).Row
                    c = .Cells(r, Columns.Count).End(xlToLeft).Offset(0, 1).Column
                    Do
                        i = i + 1
                        Set f = .Range("A:A").FindNext(f)
                    Loop While Not f Is Nothing And fa <> f.Address
                    If i > 1 Then
                       sMsg = "More than one match found."
                    Else
                        sMsg = "Done"
                        .Cells(r, c) = txtCount.Text
                    End If
                        
                Else
                    sMsg = "'" & txtSearch.Text & "' not found."
                End If
        End With
    End If
    MsgBox sMsg
    End Sub

  3. #3
    Registered User
    Join Date
    06-06-2016
    Location
    London
    MS-Off Ver
    2010
    Posts
    50

    Re: Search String then add data next to it.

    exactly what I wanted, thank you super star

  4. #4
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,117

    Re: Search String then add data next to it.

    You're very welcome. Thank you for the feedback.

+ 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. string search and data modificatoin
    By lotsa? in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-08-2018, 09:24 AM
  2. Search within a string and return data
    By VegasL in forum Excel General
    Replies: 2
    Last Post: 04-19-2018, 11:58 PM
  3. Replies: 2
    Last Post: 01-02-2013, 08:35 AM
  4. [SOLVED] Search for string across header row, then search for another string down found column
    By TucsonJack in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-14-2012, 02:09 PM
  5. Search for word in a string of data
    By Cydney in forum Excel General
    Replies: 2
    Last Post: 02-11-2009, 11:58 AM
  6. [SOLVED] to search for a string and affect data if it finds the string?
    By Shwaman in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-10-2006, 09:00 PM
  7. search a string withing a string : find / search hangs
    By itarnak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2005, 11:05 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