+ Reply to Thread
Results 1 to 6 of 6

If name is the same between two sheets, have certain columns populate data

Hybrid View

  1. #1
    Registered User
    Join Date
    02-16-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    If name is the same between two sheets, have certain columns populate data

    Ok new to programming VBA first off.

    My problem is I have two sheets they both contain a long series of names, some of the names between the two sheets are the same.

    For each name there are four columns containing data that I filled out.

    Im wanting names that match between the two sheets to have that data in the four columns auto populate

    Names are in Column A
    Data in columns E through H

    thanks in advance for the help.

  2. #2
    Registered User
    Join Date
    02-16-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: If name is the same between two sheets, have certain columns populate data

    Help please, Im sure this is easy for someone.

  3. #3
    Registered User
    Join Date
    02-09-2013
    Location
    Bratislava
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    11

    Re: If name is the same between two sheets, have certain columns populate data

    If you change last row in cell A in Sheet1 the macro find in the Sheet2 the same name and copy the four values from Sheet2 columns E-H to Sheet1 to columns E - H.

    Code for Sheet1:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim LRow As Integer
    LRow = Range("A" & Rows.Count).End(xlUp).Row
    
     If Target.Address = Range("A" & LRow).Address Then
        Call FindNameCopyValues
    End If
    End Sub
    and code for Module:
    Sub FindNameCopyValues()
    
        Dim LastRow As Integer
        Dim MyValue As Variant
        Dim rng As Range
        
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
        MyValue = Range("A" & LastRow).Value
          
        With Sheets("Sheet2").Range("A:A")
        
            Set rng = .Find(What:=MyValue, _
                      After:=.Cells(.Cells.Count), _
                      LookIn:=xlFormulas, _
                      LookAt:=xlWhole, _
                      SearchOrder:=xlByRows, _
                      SearchDirection:=xlNext, _
                      MatchCase:=False)
                        If Not rng Is Nothing Then
                           rng.Offset(, 4).Resize(, 4).Copy Range("E" & LastRow, "H" & LastRow)
                        End If
        End With
    End Sub
    Here is the file:
    data.xls
    Last edited by PushCar; 02-17-2013 at 07:57 AM.

  4. #4
    Registered User
    Join Date
    02-16-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: If name is the same between two sheets, have certain columns populate data

    Thanks that is a start, but I need it to not just check the last row... For instance if 20 names are pasted into sheet two I need them to all auto populate the four columns if they were in the previous sheet, sheet1...

    Thanks again for the help.
    Last edited by steinhk6; 02-17-2013 at 07:26 PM.

  5. #5
    Registered User
    Join Date
    02-09-2013
    Location
    Bratislava
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    11

    Re: If name is the same between two sheets, have certain columns populate data

    If you only pasted into sheet two, this is for you:

    Code for Sheet2:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        If Not Intersect(Target, Columns("A")) Is Nothing Then
      
        Dim LRow As Integer
        Dim LRows As Integer
        Dim MyArray As Variant
        Dim MyValue As Variant
        Dim ValCount As Integer
        Dim AdrVal As String
            
        LRows = Range("A" & Rows.Count).End(xlUp).Row
        LRow = Range("E" & Rows.Count).End(xlUp).Row
        MyArray = Selection
        ValCount = Selection.Rows.Count
        AdrVal = Selection.Columns.Address
            
            With Sheets("Sheet1").Range("A:A")
    
                For i = 1 To ValCount
    
                    If ValCount > 1 Then
                        MyValue = MyArray(i, 1)
                    Else
                        MyValue = MyArray
                    End If
        
                        Set rng = .Find(What:=MyValue, _
                            After:=.Cells(.Cells.Count), _
                            LookIn:=xlFormulas, _
                            LookAt:=xlWhole, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlNext, _
                            MatchCase:=False)
                            
                            If Not rng Is Nothing Then
                            
                            On Error Resume Next
                            rng.Offset(, 4).Resize(, 4).Copy Range(AdrVal).Rows(i).Offset(, 4).Resize(, 4)
                            On Error GoTo 0
                        
                            End If
                            
                Next i
        
            End With
    
        End If
    End Sub
    Here is the file:
    data.xls

  6. #6
    Registered User
    Join Date
    02-16-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: If name is the same between two sheets, have certain columns populate data

    Hmmm, that isn't working right...

    The data from column A is moving into column B.

    I still need the data from E-H Columns to auto populate for any name from A column that matched from sheet1 to sheet2.

    Thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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