Find Value In Column & Copy Entire Row

Important Notice


Please note that on 14th December 2023 users will experience an expected outage whilst we make upgrades to our network. We anticipate this process may take a couple of hours and so we apologise in advance for any inconvenience.

  • thanks for that simon.


    i have another small question, related to this.


    what would be the best way to search for a value in a cell (an unique one) using an input box and then if the value is found copying the whole row of the cell onto a new worksheet in the next available row within a table.


    I am currently using the following archaic codes:


    x$ = InputBox("Please Enter Catalogue Number")


    For i = 4 To 500


    If Sheet2.Cells(i, 1) = x$ Or Sheet2.Cells(i, 7) = x$ Or Sheet2.Cells(i, 8) = x$ Or Sheet2.Cells(i, 9) = x$ Then


    Sheet1.Cells(6, 1) = Sheet2.Cells(i, 1)
    Sheet1.Cells(6, 2) = Sheet2.Cells(i, 2)
    Sheet1.Cells(6, 3) = Sheet2.Cells(i, 3)
    Sheet1.Cells(6, 4) = Sheet2.Cells(i, 4)
    Sheet1.Cells(6, 5) = Sheet2.Cells(i, 5)
    Sheet1.Cells(6, 6) = Sheet2.Cells(i, 6)
    End If


    Next i


    End Sub


    this has the problem that i can't fit it to the next available row and have to be specific for each row.


    it would also be great if i could put a messagebox in cases where the data is not found, basically saying that the item does not exist and if a simple excel Ctrl+F button or something similar could be attached to the msgbox so that the item can be searched and then added to the next available row.


    Thanks for the help in advance!

  • Re: Copy Rows Between Sheets


    Try this:

    Code
    Sub Macro1()
    Dim Ib As String
    Dim rFound As Range
    Ib = Application.InputBox("Enter Catalogue number", "Catalogue Number", , , , , , 1)
       rFound = Cells.Find(What:=Ib, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Address
            Range(rFound).EntireRow.Copy Destination:=Sheets("Report").Range("A65536").End(xlUp).Offset(1, 0)
    End Sub
  • Re: Copy Rows Between Sheets


    really appreciate your help. but the inputbox command seems to have some problem in it. i have attached the worksheet. please let me know what i am doing wrong.


    thanks in advance![hr]*[/hr] Auto Merged Post Until 24 Hrs Passes;[dl]*[/dl]help!!!

  • Re: Find Value In Column & Copy Entire Row


    You didnt explain that catalogue numbers were made up of Characters and figures!!!
    try replacing:

    Code
    Ib = Application.InputBox("Enter Catalogue number", "Catalogue Number", , , , , , 1)

    with:

    Code
    Ib = InputBox("Enter Catalogue number", "Catalogue Number")
  • Re: Find Value In Column & Copy Entire Row


    Code
    copying the whole row of the cell onto a new worksheet


    I don’t think you mean a “new” worksheet, but an existing worksheet, namely sheet1, “Sales”


    Why are you comparing the value entered in the Inputbox to sheet2 columns G,H and I?


    Attached are two files.


    The first has a button on Sheet1 to call an inputbox per your request.


    The second file is a suggestion. Select a cell in column A of the Sales sheet then select a Catalog Number from the drop down box. (Notice there is a “Cancel” item in this list to cancel a previously entered Number.)


    I notice you have at least one Catalog Number entered twice. The second file will allow selecting any duplicate Catalog Numbers, but you can’t see the other information about the Number to help make a decision as to which Number to select. (You can't do this with an inputbox.)


    In general, duplicate numbers are an invitation to problems in your code down the road. I would suggest a suffix to the number to make them unique.


    E.G.
    F-530SA
    F-530SB



    Another way to select Catalog Nubmers is to use a single Combobox on the Sales sheet. The drop down list in the Combo box could show all or selected information about the Catalog Number.
    It would work like a combination of teh two attached files.

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: Find Value In Column & Copy Entire Row


    mate, that is awesome! both files are working perfectly. i will add a suffix and make the duplicates unique. thanks so much for the help and advice

  • Re: Find Value In Column & Copy Entire Row


    Attached is another sample file using a checkbox and combobox on the sales sheet.


    To add items to the order select a product from the combo box drop down list.


    To insert an item click on the insert check box, select the ordered item row were you want the insertion, then select the item to insert from the combobox drop down list.


    To cancel an item, select it, then select the cancel item from the combobox drop down list.

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!