+ Reply to Thread
Results 1 to 3 of 3

Check if data in Sheet1 matches with Sheet2 and then update sheet1

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Check if data in Sheet1 matches with Sheet2 and then update sheet1

    Hi All

    I got stuck in a problem. Please see attached the workbook. There is data present in Sheet1 and Sheet2.I want to check the following things:

    1. For each record in Sheet1, If "F" column stores "list work" then don't do anything and move to step 2.

    2. Check for each record, If data in "F" column of Sheet1 matches with "H" column data of sheet2 then store the value of corresponding "E" column of sheet2 in "G" column of sheet1.

    3. If it doesn't match then leave that record and move to next record of sheet2.
    I tried writing the following code but it doesn't work:
    
     Dim cn As ADODB.Connection
    
      Dim rs As ADODB.Recordset
    
      Set cn = New ADODB.Connection
    
      cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
    
            "Data Source=J:\ABC.mdb;"
    
     
    
      Set rs = New ADODB.Recordset
    
     Dim wb As Workbook
    
     Dim ws As Worksheet
    
     Set wb = ActiveWorkbook
    
         Dim i As Integer
    
         Dim j As Integer
    
         Dim strsql As String
    
     
    
    Set ws = ThisWorkbook.Worksheets("sheet1")
    
    Set ws1 = ThisWorkbook.Worksheets("sheet2")
    
    For i = 2 To 282
    
    For j = 2 To 135
    
    If ws.Cells("F", i).Value = "list work" Then
    
    Exit For
    
    Else
    
    If ws.Cells("F", i).Value = ws1.Cells("H", j) Then
    
    ws.Cells("G", i).Value = ws1.Cells("H", j)
    
    Exit For
    
    Else
    
    Next j
    
    End If
    
    Next j
    
    Next i
    Can anyone please help me in this?

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Check if data in Sheet1 matches with Sheet2 and then update sheet1

    Hi Guys
    I am getting type mismatch error at the red line in the following code:
    Private Sub Workbook_Open()
      Dim cn As ADODB.Connection
      Dim rs As ADODB.Recordset
      Dim r As Long
        ' connect to the Access database
      Set cn = New ADODB.Connection
      cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
            "Data Source=J:\WilliamsLea-AIMM\Unit Rate MI\Alice's Adventures in Wonderland\The Mad Hatter\WorkQueue.mdb;"
            
     Set rs = New ADODB.Recordset
     Dim wb As Workbook
     Dim ws As Worksheet
     Set wb = ActiveWorkbook
    
         Dim i As Integer
         Dim j As Integer
         Dim strsql As String
         
    Set ws = ThisWorkbook.Worksheets("sheet1")
    Set ws1 = ThisWorkbook.Worksheets("sheet2")
    
    For i = 2 To 282
    For j = 2 To 135
    If ws.Cells("F", i).Value = "list work" Then
    Exit For
    ElseIf ws.Cells("F", i).Value = ws1.Cells("H", j) Then
    ws.Cells("G", i).Value = ws1.Cells("H", j)
    Exit For
    End If
    Next j
    Next i
    End Sub

  3. #3
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Check if data in Sheet1 matches with Sheet2 and then update sheet1

    sorted guys. I was writing rows n columns values other way around. Thanks anyway.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. move data from sheet1 to sheet2 based on date in column1 of sheet1
    By pcaldwell in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-10-2014, 03:20 PM
  2. Copy Data from Sheet1 to Sheet2 depending on input on Sheet1
    By jjmitchell88 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-25-2014, 04:33 PM
  3. Replies: 6
    Last Post: 07-25-2013, 02:58 PM
  4. [SOLVED] Take Data From Column on Sheet1 and Insert Into Next Blank Row on Sheet2 Then Clear Sheet1
    By abutler911 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-09-2013, 06:30 PM
  5. Replies: 3
    Last Post: 06-06-2012, 05:36 AM

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