+ Reply to Thread
Results 1 to 3 of 3

Read text and find the corresponding value in another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    07-01-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003
    Posts
    8

    Read text and find the corresponding value in another worksheet

    Hi,

    I am new to VBA and need a macro to do the following for me

    1. Read the text in Sheet 1 - Column A.
    2. Find that text in Sheet 2 -Column B
    3. If found, copy the corresponding value in Column A of Sheet 2 and paste it in Column B of sheet 1.

    4. If not found, leave the column blank.

    5. Repeat the above for each row in column A of Sheet1.

    I have attached a sample worksheet.

    In brief, I want the macro to read each text in every row of column A(Sheet1) and search it in column B of sheet 2. If found, copy the corresponding value in Column A of sheet2 to corresponding column B of sheet one of the text being searched.

    Thanks for helping me out
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Read text and find the corresponding value in another worksheet

    try this:

    updated example in attachment

    Private Sub CommandButton1_Click()
    Dim r As Integer
    Dim from, dest As Object
    
    Set dest = Sheets("Sheet1")
    Set from = Sheets("Sheet2")
    
    For r = 1 To dest.UsedRange.Rows.Count
      On Error Resume Next
      dest.Cells(r, 2).Value = from.Range("B:B").Find(dest.Cells(r, 1).Value, SearchOrder:=xlByRows).Offset(, -1).Value
    Next r
    End Sub
    Best Regards
    MaczaQ
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    07-01-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Read text and find the corresponding value in another worksheet

    Thanks Mac .... Works like a charm

+ 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