+ Reply to Thread
Results 1 to 17 of 17

Extract data based on cells names across sheets

  1. #1
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Extract data based on cells names across sheets

    Hello
    I have many spesific cells and columns containns names , what I want matching amongst sheets DETAILS with TABLE 3,TABLE 4 then should brings all of data where next to adjacent cell for cell name or under it .
    the cells ,columns as I put in sheet DETAILS(DISTRIBUTOR CODE,SHIPMENT DATE,DESTINATION,PRODUCT CODE,BRAND,QTY,TOTAL SHIPMENT QTY,CONTR#,SEAL#). and if the rows are alittle and the BRAND are more than rows inserted in sheet DETAILS then should add before TOTAL SHIPMENT QTY rows with the same borders . and if there is duplicate item as column B( BARND) should merge and sum the values whether duplicates item are in the same sheet or across sheets as in item 1,4 as I put the result in sheet expected . as to TOTAL SHIPMENT QTY,DISTRIBUTOR CODE,SHIPMENT DATE will repeat for each separated range should just choose one of them and ignore the rest .
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Extract data based on cells names across sheets


    Hello,

    each time both source data worksheets are for the same disdributor ?
    If not attach a better workbook sample well reflecting the case ...

  3. #3
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Extract data based on cells names across sheets

    Hi Marc
    each time both source data worksheets are for the same disdributor ?
    yes multiple separated range for the same distributor . what's the problem for this ?
    when you get the value in sheet details will bring the same value . as I said
    as to TOTAL SHIPMENT QTY,DISTRIBUTOR CODE,SHIPMENT DATE will repeat for each separated range should just choose one of them and ignore the rest .

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    According to your attachment a VBA demonstration for starters to paste to the Worksheet____1 (Details) worksheet module :

    PHP Code: 
    Sub Demo1()
      Const 
    13
        Dim N
    &, Rg As RangeM&, W(), L&, R&, VC%
            
    With Sheets(2):  [B1] = .[B1]:  [B2:B3] = .[D1:D2].Value:  End With
        
    For 2 To 3
        
    For Each Rg In Sheets(N).UsedRange.Columns(1).SpecialCells(2).Areas
            M 
    1
            ReDim Preserve W
    (1 To M)
            
    W(M) = Rg.CurrentRegion
        Next Rg
    N
        With 
    New Collection
            
    For 2 To M Step 2
            
    For 2 To UBound(W(N))
                
    W(N)(LG) = CStr(W(N)(LG))
            For 
    1 To .Count
                   V 
    StrComp(.Item(R), W(N)(LG))
                If 
    >= 0 Then
                    
    If V Then .Add W(N)(LG), , R
                    
    Exit For
                
    End If
            
    Next
                
    If > .Count Then .Add W(N)(LG)
            
    Next LN
                
    For 1 To .Count:  .Add R, .Item(R), R:  .Remove R 1:  Next
                ReDim V
    (1 To .CountK)
            For 
    2 To M Step 2
            
    For 2 To UBound(W(N))
                    
    = .Item(W(N)(LG))
                If 
    IsEmpty(V(RG)) Then
                    V
    (R0) = R
                    
    For 1 To K:  V(RC) = W(N)(LC):  Next
                
    Else
                    
    V(RK) = V(RK) + W(N)(LK)
                
    End If
            
    Next LN
                R 
    = .Count
        End With
            L 
    4
            
    If 0 Then Rows(8).Resize(L).Insert14 Else 14
        With 
    [A6].Resize(R1)
            .
    Value V
            
    .Cells(11) = Application.Sum(.Columns(1)) & " pcs"
        
    End With
            ReDim V
    (1 To M 21 To 3)
            
    0
        
    For 1 To M 1 Step 2
            R 
    1
            V
    (R1) = R
            V
    (R2) = W(N)(22)
            
    V(R3) = W(N)(32)
        
    Next
            
    If 3 Then Rows(1).Resize(3).Insert
            Cells
    (L1).Resize(R3) = V
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon ? Add Reputation ? !

  5. #5
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Extract data based on cells names across sheets

    Thanks , but doesn't arrange data as I expect . you can see so.
    Attached Files Attached Files

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: Extract data based on cells names across sheets


    No issue on my side and as I wrote 'According to your attachment' so try at least with exactly the same initial post attachment !

  7. #7
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Extract data based on cells names across sheets

    No issue on my side and as I wrote 'According to your attachment'
    strange !!
    so try at least with exactly the same initial post attachment !
    actually the same file.
    well, I will check it again and come back soon.

  8. #8
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Extract data based on cells names across sheets

    the problem still continues

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Extract data based on cells names across sheets


    As I won't guess what you have done so download first the post #1 attachment and try with it as it is in post #1 ...
    Last edited by Marc L; 10-15-2022 at 08:59 AM.

  10. #10
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Extract data based on cells names across sheets

    OK this problem occures when run macro more than one time .I accep to t clear data in sheet details before brings data to replace data if update in others sheets. how can I fix this problem,please?

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Extract data based on cells names across sheets


    As it was according to your iniitial explanation with rows to be inserted etc ...

    If you need to keep the Details worksheet cell formatting so you will need to amend this worksheet
    with adding the SUM formula in cell D10 and naming two ranges
    or if you don't need to keep the actual cell formatting an easy way is to clear the Details worksheet and copy the raw data ?

    As it depends also on what you forgot to explain in your initial post :
    does some data need to be sorted or just keep the original order ?
    The better explanation, the less mods you will have to do ...

  12. #12
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Extract data based on cells names across sheets

    actually I want to keep the Details worksheet cell formatting.
    when sort the data de[depends on column B . as you see sort numbers from small to big .
    your code does work as what I want except clear data before brings any thing to replace the last updating .

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Extract data based on cells names across sheets


    Sort only products in second range, but about the third range (seals) ?

  14. #14
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Extract data based on cells names across sheets

    Ok also should sort from small to big about third range(seals)

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Re: Extract data based on cells names across sheets


    According to your initial post attachment and to Excel basics you must first name two ranges in Details worksheet :

    • cells A5:D10 as _PRODUCTS

    • cells A13:C16 as _SEALS


    Download the below attachment and rename it just removing at end .txt in order it becomes a .cls file.


    Import this Sorted Collection class module file on VBE side via a right click on your project.
    Once done you must see the SCollection class module within your VBA project.


    Once ranges named and the class module imported try this new VBA demonstration for starters
    to paste only to the Worksheet____1 (Details) worksheet module :

    PHP Code: 
    Sub DemoSCollection1()
      Const 
    1
        Dim N
    &, W(), M&, L&, oCol As New SCollectionK%, V(), R&, C%
        For 
    2 To 3
            With Sheets
    (N).UsedRange.Columns(1).SpecialCells(2).Areas
                ReDim Preserve W
    (1 To M + .Count)
                For 
    1 To .Count:  1:  W(M) = .Item(L).CurrentRegion.Value2:  Next
            End With
        Next
            
    [B1:B3] = Application.Transpose(Array(W(1)(12), W(1)(14), W(1)(24)))
        
    With [_PRODUCTS].Rows
           
    .Item("2:" & .Count 1).ClearContents
            
    For 2 To M Step 2:  oCol.AddColumn W(N), 2G:  Next
            
    If oCol.Count Then oCol.IndexItemsAsKeys Else Exit Sub
            K 
    = .Columns.Count 1
            ReDim V
    (1 To oCol.CountK)
        For 
    2 To M Step 2
        
    For 2 To UBound(W(N))
                
    oCol(W(N)(LG))
            If 
    IsEmpty(V(RG)) Then
                V
    (R0) = R
                
    For 1 To K:  V(RC) = W(N)(LC):  Next
            
    Else
                
    V(RK) = V(RK) + W(N)(LK)
            
    End If
        
    Next LN
           
    .Cells(.Count1) = W(1)(54)
            If 
    oCol.Count > .Count 2 Then .Item(3).Resize(oCol.Count - .Count 2).Insert
           
    .Item(2).Resize(oCol.Count) = V
        End With
            oCol
    .Reset
        With 
    [_SEALS].Rows
           
    .Item("2:" & .Count).ClearContents
            
    For 1 To M 1 Step 2:  oCol.Add W(N)(32):  Next
            
    If oCol.Count Then oCol.IndexItemsAsKeys Else Exit Sub
            ReDim V
    (1 To oCol.Count1 To .Columns.Count)
            For 
    1 To M 1 Step 2:  oCol(W(N)(32)):  V(R1) = R:  V(R2) = W(N)(22):  V(R3) = W(N)(32):  Next
            
    If oCol.Count >= .Count Then .Item(3).Resize(oCol.Count - .Count).Insert
           
    .Item(2).Resize(oCol.Count) = V
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon ? Add Reputation ? !
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    02-08-2021
    Location
    africa
    MS-Off Ver
    2016
    Posts
    413

    Re: Extract data based on cells names across sheets

    despite of the code became complex but the code works greatly
    thanks very much

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Extract data based on cells names across sheets


    Thanks for the rep' !

    The sorted Collection class module simplifies the VBA procedure like you can compare with the first demonstration.

    If your real workbook has the same few data
    so a beginner level Excel basics VBA procedure can achieve the same result in the same short time ...

+ 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] match data between two sheets based on names and auto fill
    By ABDELFATTA in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-20-2021, 10:57 AM
  2. [SOLVED] split data from sheet to three sheets for many names based on two columns
    By leap out in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-14-2021, 10:02 AM
  3. Extract Data based on Attributes from multiple sheets
    By balle123 in forum Excel General
    Replies: 3
    Last Post: 06-20-2017, 05:25 AM
  4. [SOLVED] Extract data from various sheets (based on sheet names) with 2 criteria
    By Shareez Saleem in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-17-2017, 06:51 AM
  5. [SOLVED] Dynamically create sheets with similar names and copy cells on row based on matched cus#
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2016, 07:33 AM
  6. Extract names of sheets to cells
    By Jaken3 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-16-2015, 11:21 AM
  7. Replies: 6
    Last Post: 03-24-2015, 04:13 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