+ Reply to Thread
Results 1 to 6 of 6

If Item on Sheet Doesn't Exist in Specified Table, Add It To Table

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    If Item on Sheet Doesn't Exist in Specified Table, Add It To Table

    Hello,

    I have a Table on the Sheet CONTROL that contains Widgets.

    There is another Sheet, called Received PT that contains a PivotTable of Widgets.

    If the Widget does not exist on the CONTROL Sheet Table, but exists on the Received PT PivotTable, I would like to add the missing Widget to the CONTROL Sheet Table.

    Any ideas? I am moderately stumped. and this would bring a long project to a close.
    Attached Files Attached Files
    Thank You,

    EnigmaMatter

  2. #2
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: If Item on Sheet Doesn't Exist in Specified Table, Add It To Table

    I have attached a workbook example.

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,996

    Re: If Item on Sheet Doesn't Exist in Specified Table, Add It To Table

    One way:
    Sub MatchUp()
        Dim rngCell               As Range
        Dim PT                    As PivotTable
        Dim lc                    As ListColumn
        Dim lo                    As ListObject
        Dim lr                    As ListRow
    
        Set PT = Sheets("Received PT").PivotTables(1)
    
        Set lo = Sheets("Control").ListObjects(1)
        Set lc = lo.ListColumns("REF#")
    
        For Each rngCell In PT.RowFields(1).DataRange.Cells
            If LenB(rngCell.Value) <> 0 Then
                If IsError(Application.Match(rngCell.Value, lc.DataBodyRange, 0)) Then
                    Set lr = lo.ListRows.Add
                    lr.Range(1).Value = rngCell.Value
                End If
            End If
        Next rngCell
    
    End Sub
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: If Item on Sheet Doesn't Exist in Specified Table, Add It To Table

    Romperstomper,

    It works beautifully. Is there a way with this code, to have the quantity move over as well? I could do it with a VLOOKUP, but that sounds messier than the beauty you put above.

  5. #5
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: If Item on Sheet Doesn't Exist in Specified Table, Add It To Table

    Thank you, again. Very much!

  6. #6
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: If Item on Sheet Doesn't Exist in Specified Table, Add It To Table

    Romperstomper,

    I was actually able to figure out the answer to my question...

       lr.Range(1).Value = rngCell.Value
       lr.Range(2).Value = rngCell.Offset(0, 1)

+ 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. [SOLVED] Pivot table calculated item doesn't calculate on Grand Total
    By nfcascalheira in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 10-27-2014, 08:10 AM
  2. Updating a pivot table with VBA from Drop down list (1st item doesn't work)
    By tray262 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-25-2013, 02:32 PM
  3. Replies: 0
    Last Post: 03-10-2013, 04:19 PM
  4. Replies: 5
    Last Post: 12-12-2012, 12:26 PM
  5. how to stop VBA overwriting Pivot Table Value if Value doesn't exist
    By karl1985 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2010, 06:47 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