+ Reply to Thread
Results 1 to 9 of 9

Macro to copy and paste values in a selected row

Hybrid View

  1. #1
    Registered User
    Join Date
    02-24-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Question Macro to copy and paste values in a selected row

    I have a database of customer details and people can use a data form to browse through to look for ID numbers. You then click on another button that has the macro i have pasted beneath and you type in the ID and it finds and selects the row it is in, i then want to copy certain values in that row and paste on another sheet in specific cells and i need this to work each time the row is different, can anyone help please???

    Here is the macro


    Sub findvalue()
    Search = Val(InputBox(prompt:="Enter Customer ID"))
    
    Columns("A:A").Select
    For Each cell In Selection
    If cell.Value = Search Then
    cell.Select
    End If
    Next cell
    
    End Sub
    Last edited by marianov; 03-05-2012 at 05:34 PM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to copy and paste values in a selected row

    Please edit your post to use code tags per the forum rules.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    02-24-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy and paste values in a selected row

    I have changed it now

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to copy and paste values in a selected row

    Thanks. If you can I think it would also help to see a workbook with a sample of your data and the result that you are expecting.

    Dom

  5. #5
    Registered User
    Join Date
    02-24-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy and paste values in a selected row

    Here is a quick example that i made, similar to the original but with less macros and sheets. I have set up the macro i posted before on the button find values and i need the button that says copy values to copy the values in whichever the row is and paste them on sheet 2 in the corresponding cells that i have made. Ignore the prices its just the name and address, email and number i need. Thanks for the help in advance!!!
    Attached Files Attached Files

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to copy and paste values in a selected row

    How about in one go?

    Sub findvalue()
    
        Dim strSearch As String
        Dim rngFindRange As Range
    
        strSearch = InputBox(prompt:="Enter Customer ID")
    
        With Sheets("Sheet1")
            Set rngFindRange = .Range("A9:A" & .Range("A" & Rows.Count).End(xlUp).Row).Find(strSearch, _
                LookIn:=xlValues, lookat:=xlWhole)
        End With
    
        If Not rngFindRange Is Nothing Then
            With Sheets("Sheet2")
                .Range("D4") = rngFindRange.Offset(0, 2)
                .Range("D6") = rngFindRange.Offset(0, 3)
                .Range("D8") = rngFindRange.Offset(0, 4)
                .Range("D10") = rngFindRange.Offset(0, 5)
                .Range("D12") = rngFindRange.Offset(0, 6)
                .Range("D14") = rngFindRange.Offset(0, 7)
                .Range("D16") = rngFindRange.Offset(0, 8)
                .Range("D18") = rngFindRange.Offset(0, 9)
                .Range("D20") = rngFindRange.Offset(0, 10)
                .Range("D22") = rngFindRange.Offset(0, 11)
            End With
        Else
            MsgBox "Customer ID not found.", vbExclamation
        End If
    
    End Sub
    Dom

  7. #7
    Registered User
    Join Date
    02-24-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy and paste values in a selected row

    Man you are a true genius. you don't realise how long i have been stuck on this. Thanks very much for help dude!! better than i expected

  8. #8
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to copy and paste values in a selected row

    Glad I could help . Please mark the thread solved if you are happy with the solution.

    Dom

  9. #9
    Registered User
    Join Date
    02-24-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Macro to copy and paste values in a selected row

    will do, thanks again!
    Last edited by marianov; 03-05-2012 at 05:28 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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