Results 1 to 8 of 8

vba code to extract data from data table and update data sheet

Threaded View

  1. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: vba code to extract data from data table and update data sheet

    Post #3 code and workbook updated to Final Versions 25 May 2017 12:50
    I didn't get an answer to my question, so I set Column AT = corresponding 'Table 1' values (Column D) in rows where no SADC was found. Hope this suits-Lee
    Sub DataSheetUpdate()
    
    Dim SourceRange As Range
    Dim DestinationRange As Range
    Dim found As Range
    Dim LookupRange As Range
    Dim sLastRow As Long
    Dim dLastRow As Long
    Dim rw As Long
    Dim WS1 As Worksheet
    Dim WS2 As Worksheet
    Dim SADCs As Boolean
    
    Set WS1 = Worksheets("table 1")
    Set WS2 = Worksheets("DATA SHEET")
    
    With WS1
        Set SourceRange = .Columns("C:F")
        sLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
        Set LookupRange = .Cells(2, "A").Resize(sLastRow - 1)
    End With
    
    With WS2
        Set DestinationRange = .Columns("AS:AV")
        dLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    
        Set found = .Columns("K").Find("SADC*(", LookIn:=xlFormulas, Lookat:=xlPart)
        If Not found Is Nothing Then
            .Cells(1, "AW").Resize(dLastRow).Copy
            .Cells(1, "AX").PasteSpecial xlPasteFormats
            .Cells(1, "AX") = "SADC"
            SADCs = True
            Application.CutCopyMode = False
        End If
    
    For rw = 2 To dLastRow
        Set found = LookupRange.Find(.Cells(rw, "I"))
        If found Is Nothing Then
            DestinationRange.Rows(rw) = "XXX"
            Debug.Print "Tariff # not found on row " & rw
        Else
            DestinationRange.Rows(rw).Value = SourceRange.Rows(found.Row).Value
            .Cells(rw, "AW").Value = WS1.Cells(found.Row, "O")
            If SADCs Then
                On Error Resume Next
                If Left(.Cells(rw, "K"), 4) = "SADC" Then
                    .Cells(rw, "AT") = 0
                    .Cells(rw, "AX") = "Y"
                Else
                    .Cells(rw, "AX") = "N"
                End If
                On Error GoTo 0
            End If
        End If
    Next
    
    End With
    
    End Sub
    Please click the Add Reputation star below any helpful posts, and if you have your answer, mark your thread as SOLVED (Thread Tools up top). Thanks!-Lee
    Attached Files Attached Files
    Last edited by leelnich; 05-25-2017 at 02:29 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA code to extract and reorganize data from table in Excel
    By Atom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2016, 01:13 PM
  2. [SOLVED] Vba code to extract data from one sheet to another
    By xlhelp7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2016, 01:17 AM
  3. Vba code to Extract data from multiple sheet
    By Masa1989 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-05-2015, 01:51 AM
  4. Replies: 3
    Last Post: 12-18-2014, 10:27 AM
  5. Replies: 1
    Last Post: 12-13-2013, 03:03 AM
  6. Replies: 1
    Last Post: 11-28-2013, 02:10 AM
  7. Search for Excel file and the sheet within that from the given table data and extract data
    By adrian_slash in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-23-2013, 07:55 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