Lookup a column of values in another worksheet and copy values

Author Message
mvdberg112

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 7/5/2010
  • Status: offline
Lookup a column of values in another worksheet and copy values Monday, July 05, 2010 3:56 AM (permalink)
0
Please, does somebody how to do this:

I have two worksheets: 1 with mail adresses, and a second one with (some of these) mailaddresses.
The script should start at top of the list, see if the mail address exists at in worksheet 2, column 5. If it does, it should copy the values to worksheet 3. If not, it should make copy the mail adress with a note to samen worksheet 3.

A search on the forums and google did not help much, only the bit below I found. Although I know a bit how VBscript works, I have a hard time in finding the right 'objects' and methods and so on. This already works:

Sub test2()
Set egmnWS = Worksheets("sheet1")
Set elnlWS = Worksheets("sheet2")
Set testWS = Worksheets("sheet3")
 testX = Cells.Find('sheet1'!$A$1, LookIn:=xlValues, LookAt:=xlPart)
 
 testWS.Cells(1, 1).Value = testX
End Sub

How to understand the parms of " testX = Cells.Find('sheet1'!$A$1, LookIn:=xlValues, LookAt:=xlPart)" ?
How does copying values from one sheet to another work?
I tried to find tutorials on this, but was not lucky in finding how to put it in a cell for example.

Thank  you!
Michael
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    Re:Lookup a column of values in another worksheet and copy values Tuesday, July 06, 2010 1:57 AM (permalink)
    0
    Just to be clear, are you doing this as a macro in excel or as a separate script?
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      mvdberg112

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 7/5/2010
      • Status: offline
      Re:Lookup a column of values in another worksheet and copy values Tuesday, July 06, 2010 12:58 PM (permalink)
      0
      Thanks for the reply!
      The script is going to be a Macro. I run it from VBScript editor with MS Excel.

      I found a way to search and compare.
      Sub test2()
       
       Set egmnWS = ThisWorkbook.Sheets("EGMN RAW sort1")
       Set elnlWS = ThisWorkbook.Sheets("Elist Active NL")
       Set testWS = ThisWorkbook.Sheets("tet")
       Set test2WS = ThisWorkbook.Sheets("test2")
       
       Set tetOffset = 4
        
        For x = 1 To 90
         
        
       testx = elnlWS.Cells(x, 4).Value
        testWS.Cells(x, 4).Value = testx
       
       If Not egmnWS.Cells.Find(testx, LookAt:=xlPart) Is Nothing Then
           
           Set testy = egmnWS.Cells.Find(testx, LookAt:=xlPart)
           testWS.Cells(x, tetOffset + 5).Value = testyv ' this fills the 5th column with found cell
        
       testWS.Cells(x, tetOffset).Value = testy
       
        
        For y = 1 To 90
       'Since I do not know how to find out in which cell the value has been found (i.e. with egmnWS.Cells.Find(testx, LookAt:=xlPart) ), I simply search again the list on an exact match of the previous found value with an IF-then statement
        If egmnWS.Cells(y, 6).Value = testy Then
          testWS.Cells(x, tetOffset + 1).Value = egmnWS.Cells(y, 1).Value
          testWS.Cells(x, tetOffset + 2).Value = egmnWS.Cells(y, 2).Value
          testWS.Cells(x, tetOffset + 3).Value = egmnWS.Cells(y, 3).Value
          testWS.Cells(x, tetOffset + 4).Value = egmnWS.Cells(y, 4).Value
        End If
       
        Next y
        End If
        Next x
       End Sub


      How can a find out the reference of a cell? I have read through a number of properties and methods, but did not find it.  There are so many.....  and I am a kind of new.
       
      #3
        ebgreen

        • Total Posts : 8227
        • Scores: 98
        • Reward points : 0
        • Joined: 7/12/2005
        • Status: offline
        Re:Lookup a column of values in another worksheet and copy values Wednesday, July 07, 2010 1:15 AM (permalink)
        0
        Ok, so to be clear what you are writing is VBA not VBScript.

        From the Excel VBA documentation, the find method returns a range collection. So to get cell information I think you would make the found cell active then I think you could use the ActiveCell object to get the column and row number.
        "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
        Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
        http://www.visualbasicscript.com/m_47117/tm.htm
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9