+ Reply to Thread
Results 1 to 5 of 5

Search cell in rows and copy paste

Hybrid View

  1. #1
    Registered User
    Join Date
    10-19-2008
    Location
    UK
    Posts
    63

    Search cell in rows and copy paste

    Hi,

    I have following data in Sheet2 in column A to C (starting A1):

    Apples France 100
    Pears Italy 50
    Bananas Guatemala 20
    Kiwis New Zealand 60
    Grapes Spain 10
    Figs Italy 80
    Melon Italy 20


    I would like to do a search through column B and if Italy is found then if number is higher than 50 (in column C) I would like the text in column A to be copied in Sheet1 starting from Cell A1 going down.

    Thanks,
    Nix
    Last edited by nicolaforni; 07-27-2011 at 12:59 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Search cell in rows and copy paste

    Sub nicolaforni()
    
        Dim i As Integer
        
        With Sheets("Sheet2")
            For i = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
                If .Cells(i, 2).Value = "Italy" Then
                    If .Cells(i, 3).Value > 50 Then Sheets("Sheet1").Cells(Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1, 1).Value = .Cells(i, 1).Value
                End If
            Next i
        End With
    
    End Sub
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    10-19-2008
    Location
    UK
    Posts
    63

    Re: Search cell in rows and copy paste

    Great.
    How would the code change if instead of looking for "Italy" I wanted to look for what is in cell E1 of Sheet1?
    Basically this way I could change search by typing different country in E1 (eg. France, Spain etc.) instead of amending code each time.

    Thanks,
    NIc

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Search cell in rows and copy paste

    Sub nicolaforni()
    
        Dim i As Integer
        
        With Sheets("Sheet2")
            For i = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
                If .Cells(i, 2).Value = Sheets("Sheet1").Cells(1,"E").Value Then
                    If .Cells(i, 3).Value > 50 Then Sheets("Sheet1").Cells(Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1, 1).Value = .Cells(i, 1).Value
                End If
            Next i
        End With
    
    End Sub

  5. #5
    Registered User
    Join Date
    10-19-2008
    Location
    UK
    Posts
    63

    Talking Re: Search cell in rows and copy paste

    Thanks!

+ 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