+ Reply to Thread
Results 1 to 10 of 10

concatenate text boxes to find combined value and copy paste alternative value into wb

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    concatenate text boxes to find combined value and copy paste alternative value into wb

    I have two text boxes in a user form. Text box one is a unique user reference, the second, the unique case reference number.
    In the sheet (marked Database) is the combined value of these two boxes (column B) which I am trying to do is concatenate the two text box values and search the database range. (Letters is the user form name)

    Once found I want to copy the value from the text box "Browse" which holds a file location and paste it into an offset cell and then make it a hyperlink.

    I'm close but can't quite finish it. Can anyone help me with what I am doing wrong?

    Private Sub CommandButton2_Click()
    Dim UserId, CaseId, SearchString As String
    
       UserId = Letters.User.Value
       CaseId = Letters.CaseNo.Value
       
    SearchString = UserId & CaseId
    
    '   Search Case Reference Number column from database based on two values in User Form
    '
    
    '
            Letters.Browse.Text.Copy
        
        With Sheets("Database").Find(What:="SearchString", LookIn:=Database.Range("B:B"), _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
        
        End With
        
        With ActiveCell.Offset(0, 51)
        Selection.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, _
        skipblanks:=False, Transpose:=False
        
        Application.cutcopypaste = False
        
        End With
        
        ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:= _
            "Letters.Browse.value", TextToDisplay:="Letter from Bank"
            
            Letters.Hide
    
    End Sub

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

    I think the .find method applies to a range not to a sheet, so maybe try changing:
    Sheets("Database").find
    to
    Sheets("Database").cells.find

  3. #3
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

    Sheets("Database").cells.find
    That gives me a Type mismatch (Error 13) message.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

    Sorry, having a closer look there are a couple other issues:
    -You are looking for the text, Searchstring, rather than the defined variable (remove the quotes to deal with this)
    -I don't think you can use the with construct like that.
    -You are telling it to look in Database.Range, I don't think Database is a valid object reference in this case
    -The lookin statement is for whether to look at the formulas or results I think, if you want to limit to a column, you need to change the range the find method is applied to.

    Maybe try:
    Sheets("Database").Range("B1:B100").Find(What:=SearchString, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Select

  5. #5
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

    Thanks,

    I didn't even realise I had put speech marks in there.

    Is the range limited to defined area on a find function or could I use the B:B option?

  6. #6
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

    Book uploaded.

    Code is in userform Letters

    Run from the Documents button on sheets("Userform")
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

        With Sheets("Database").Range("B1:B100")
        .Find(What:=SearchString, After:=ActiveCell, LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False).Select
    This code isn't working but I cannot see where the issue may be

  8. #8
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

    Hi, you can use an entire column
    .columns(2)
    .range("B1").entirecolumn)
    .range("B:B")
    .columns("B")
    etc.

    I tested that code before I posted it and it ran ok - please can you upload an example workbook for which it doesn't work?

  9. #9
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

    Try:

    on error resume next
    Sheets("Database").Cells(WorksheetFunction.Match(SearchString, Sheets("Database").Range("B1:B10"), 0), 51).Value = Letters.Browse.Value
    on error goto 0
    Instead - note you will get an error if the searchstring isn't found, the on error resume next just means the code will "skip" the error.

  10. #10
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    640

    Re: concatenate text boxes to find combined value and copy paste alternative value into wb

    on error resume next
    Sheets("Database").Cells(WorksheetFunction.Match(SearchString, Sheets("Database").Range("B1:B10"), 0), 51).Value = Letters.Browse.Value
    on error goto 0
    This is close but the value in database should be a hyperlink and I need to be able to set the name (texttodisplay) using one of the text boxes in the user form
    Last edited by Sc0tt1e; 03-10-2014 at 12:31 PM.

+ 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. how to concatenate alternative text values
    By genetist in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 07-05-2013, 04:49 AM
  2. VB - Need to optimise/alternative to copy and paste
    By scaifie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-13-2011, 06:07 PM
  3. Alternative copy & paste
    By mali90 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2011, 06:57 AM
  4. [SOLVED] copy and paste from text boxes
    By enyaw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-02-2006, 08:00 AM
  5. [SOLVED] is there a better alternative to Copy/Paste?
    By MichaelC in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-08-2005, 08:05 PM

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