+ Reply to Thread
Results 1 to 15 of 15

copy highlighted data for multiple colors from many sheets to another

  1. #1
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    copy highlighted data for multiple colors from many sheets to another

    hello
    I have some items in column B contain different color in sheet1,2,3. what I want coping the the whole range for the highlighted item contains color from sheet1,2,3 to sheet COPY except the range in the header and when clear the color from column B in sheet1,2,3 should change by delete the whole range from sheet COPY and if highlight new ranges , then should also copy to sheet2 . with considering when copy data to sheet COPY should sort in column B based on number from small to big
    the result in sheet copy .
    thanks
    Attached Files Attached Files
    Last edited by Ali-M; 02-23-2022 at 05:56 AM.

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: copy highlighted data for multiple colors from many sheets to another

    Hi Ali-M,

    I got a little confused with your request so i have done what i think you are trying to do - at least it will be a start:

    Please Login or Register  to view this content.
    Hope this helps

  3. #3
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: copy highlighted data for multiple colors from many sheets to another

    thanks . just I need fixing the headers. the code clear the headers from sheet COPY.

  4. #4
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: copy highlighted data for multiple colors from many sheets to another

    Hmm, i had missed a couple of full stops from the code within the With statements - try:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: copy highlighted data for multiple colors from many sheets to another

    still clear the headers .
    attached file
    Attached Files Attached Files

  6. #6
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,359

    Re: copy highlighted data for multiple colors from many sheets to another

    I see what was happening - as the table was empty it was deleting the headers - i have added a check in there now so it will not clear the table if it is already empty:

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: copy highlighted data for multiple colors from many sheets to another

    seems slow despite of it's simple data , but if even if it's thanks so much

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

    Cool Hello, try this !


    According to your attachment a VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
            
    Dim S&, VWL&, R&, C%
        
    With Worksheet____2
            
    .UsedRange.Offset(1).Clear
        
    For 1 To .Index 1
            With Sheets
    (S).[A1].CurrentRegion.Columns
                    
    If 1 Then ReDim V(1 To Rows.Count 11 To .Count)
                    
    = .Value2
                
    For 2 To .Rows.Count
                    
    If .Cells(L2).Interior.ColorIndex <> xlColorIndexNone Then
                        R 
    1
                        V
    (R1) = R
                        
    For 2 To .Count:  V(RC) = W(LC):  Next
                    End 
    If
                
    Next
            End With
        Next
            
    If R Then
                With 
    .[A2].Resize(R1)
                     .
    Borders.Weight 2
                     
    .Font.Size = .Cells(01).Font.Size
                     
    .HorizontalAlignment xlCenter
                     
    .VerticalAlignment xlCenter
                     
    .Value2 V
                     
    .Columns(2).Resize(, 2).Sort .Cells(2), 1Header:=2
                End With
            End 
    If
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 02-24-2022 at 08:50 AM.

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

    Arrow Re: copy highlighted data for multiple colors from many sheets to another


    According to your last attachment just replace in my VBA demonstration Worksheet____2 with sheet2

  10. #10
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: copy highlighted data for multiple colors from many sheets to another

    @Marc L much appreciated for your code . this better , but I have problem about number format . it deosn't show like this 1,200.00 or 120.00 even if I use manually by using cell format . the code deletes it . may you fix it please?

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

    Arrow With the number format …


    Thanks for the rep' !

    PHP Code: 
    Sub Demo1()
            
    Dim S&, VWL&, R&, C%
        
    With sheet2
            
    .UsedRange.Offset(1).Clear
        
    For 1 To .Index 1
            With Sheets
    (S).[A1].CurrentRegion.Columns
                    
    If 1 Then ReDim V(1 To Rows.Count 11 To .Count)
                    
    = .Value2
                
    For 2 To .Rows.Count
                    
    If .Cells(L2).Interior.ColorIndex <> xlColorIndexNone Then
                        R 
    1
                        V
    (R1) = R
                        
    For 2 To .Count:  V(RC) = W(LC):  Next
                    End 
    If
                
    Next
            End With
        Next
            
    If R Then
                With 
    .[A2].Resize(R1).Columns
                     
    .Borders.Weight 2
                     
    .Font.Size = .Cells(01).Font.Size
                     
    .HorizontalAlignment xlCenter
                     
    .Item("F:H").NumberFormat Sheets(1).[F2].NumberFormat
                     
    .VerticalAlignment xlCenter
                     
    .Value2 V
                     
    .Item("B:H").Sort .Cells(2), 1Header:=2
                End With
            End 
    If
        
    End With
    End Sub 

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

    Lightbulb Another way, could be a bit faster …


    According to Excel basics the filter VBA demonstration :

    PHP Code: 
    Sub Demo2()
            
    Dim S&, T&, R&
        
    With sheet2
           
    .UsedRange.Offset(1).Clear
            Application
    .ScreenUpdating False
        
    For 1 To .Index 1
            With Sheets
    (S).UsedRange.Columns("B:H")
                .
    Item(8).Value2 1
                
    .Item(1).AutoFilter 1, , 12
                
    .Item(8).SpecialCells(12).Value2 0
                
    .AutoFilter
                 T 
    Application.Sum(.Item(8))
              If 
    T Then
                
    .Item(8).AutoFilter 11
                
    .Offset(1).Copy sheet2.Cells(22)
                .
    AutoFilter
                 R 
    T
              End 
    If
                .
    Item(8).Clear
            End With
        Next
        
    If R Then
            With 
    .UsedRange.Rows("2:" 1).Columns
                 
    .Item(2).Interior.ColorIndex xlColorIndexNone
                 
    .Sort .Item(2), 1Header:=2
                 
    .Item(3).Copy .Item(1)
                 .
    Item(1).Value2 Evaluate("ROW(1:" ")")
            
    End With
        End 
    If
            
    Application.ScreenUpdating True
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  13. #13
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: copy highlighted data for multiple colors from many sheets to another

    just curiosity , I heard from some members the filtering way is better choice than any other way about the speed if the data is big , but I tested it and gives the same running speed 0.1 as in post#11 . what the main reason you think ?

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

    Arrow Re: copy highlighted data for multiple colors from many sheets to another


    All I can say :

    • On my side with your attachment as it is Demo2 is a very little bit faster than Demo1, just by eyes,
      even with the screen updating desactivated in Demo1 …

    • So it may depend on the Excel version - my tests are under Excel 2010 - and on the computer as well (old slow for my tests).

    • But for sure Excel features like worksheet functions, filter, advanced filter, sort, … are already compiled
      so faster than any bad looping VBA code which must be interpreted then pre-compiled before its execution …
      I saw a kid - summer job - operating manually a huge table just with Excel basics faster than a bad looping code !

    • And obviously it depends on the logic used like copying cell by cell is slower than copying block of rows …


    What is the best code ?

    The faster ? Not always … but the one you understand, the easier to maintain by yourself !
    Imagine for some reason your office does not have any net connection
    but your boss asks you an urgent 'little mod' and expects a result in the next half hour, you well see now !
    Last edited by Marc L; 02-25-2022 at 08:32 AM. Reason: typo …

  15. #15
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: copy highlighted data for multiple colors from many sheets to another

    @thanks Marc L

+ 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] search files across multiple sheets based on cell value and highlighted
    By leap out in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-08-2021, 08:23 AM
  2. [SOLVED] copy the last entering data and show addresses sheets and cells from multiple sheets
    By ABDELFATTA in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-18-2021, 12:27 PM
  3. Replies: 3
    Last Post: 04-02-2020, 02:28 AM
  4. [SOLVED] Need VB script counting colors of highlighted cells.
    By alexgempesaw in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2015, 11:55 PM
  5. Need VB script counting colors of highlighted cells.
    By alexgempesaw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2015, 05:22 AM
  6. Need VB script counting colors of highlighted cells.
    By alexgempesaw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2015, 05:22 AM
  7. Macro for lookup in multiple sheets and highlighted columns
    By Peteaussi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2010, 06: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