Consulting

Results 1 to 3 of 3

Thread: Two Columns (Search and Copy)

  1. #1
    VBAX Newbie
    Joined
    Jul 2011
    Posts
    1
    Location

    Two Columns (Search and Copy)

    I have a column (A1:A3257) With names and Another column with Names (C1:C5288). The names in the first column are included in the second column. Next to the Names of the Second Column, I have a third column (D1:5288) with Values (eg. Grades). I want a code which looks for the name of the first column from the second column and copy the value of the third column (eg. Grades) to another column (doesnt matter the numer) in the excel sheet. In other words, I have 10 names and a column with 50 names with their grades. I want to search the names of the first column and find their grade from the column with 50 names.

    I am really fresher in macro commands. Can anyone help me please? Thank you very much for your time.

    Dem

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    Why do you need vba when vlookup does the job? With column names in row 1, in B2: =VLOOKUP(A2,C1:D5288,2,)

  3. #3
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    [vba]Sub Grades()
    ActiveWorkbook.Sheets(1).Activate
    Range("A1").Activate
    Dim cell As Range, cell2 As Range
    Dim name As String
    Dim crow As Long, i As Long, grade As Long, gT As Long
    For Each cell In Range("A1:A5")
    i = 2
    name = cell.Value
    crow = cell.row

    For Each cell2 In Sheets(2).Range("A1:A25")

    If cell2.Value = name Then
    grade = cell2.Offset(0, 1).Value
    Sheets(1).Cells(crow, i).Value = grade
    gT = gT + grade
    i = i + 1
    End If
    Next cell2
    Sheets(1).Cells(crow, i).Value = gT
    gT = 0
    Next cell

    End Sub
    [/vba]

    like this?
    Attached Files Attached Files
    ------------------------------------------------
    Happy Coding my friends

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •