+ Reply to Thread
Results 1 to 4 of 4

Macro extract data based on color background

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-22-2013
    Location
    Pekanbaru, Indonesia
    MS-Off Ver
    Excel 2013 & Google Sheet
    Posts
    1,146

    Macro extract data based on color background

    hi all,

    i am looking macro code to extract data from sheet1 to sheet2 & sheet3, with criteria background color :
    1) extract data from sheet1 to sheet2 for data contains/highlighted yellow color background
    2) extract data from sheet1 to sheet3 for data contains/highlighted red color background

    for detail information, please see attached workbook..

    any assistance would be greatly appreciated..

    regards

    john m
    Attached Files Attached Files

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Macro extract data based on color background

    Hi John M,
    try it
    Sub ertert()
    Dim i&, clr
    Application.ScreenUpdating = False: i = 1
    With Sheets("Sheet1").Range("A1").CurrentRegion
        .Parent.AutoFilterMode = False
        For Each clr In Array(vbYellow, vbRed)
            i = i + 1
            .AutoFilter Field:=2, Criteria1:=clr, Operator:=xlFilterCellColor
            .Offset(2).Copy Sheets("Sheet" & i).Range("A1")
        Next
        .AutoFilter
    End With
    Application.ScreenUpdating = True
    End Sub

  3. #3
    Forum Contributor
    Join Date
    04-24-2012
    Location
    Karlstad, Sweden
    MS-Off Ver
    Excel 2016
    Posts
    232

    Re: Macro extract data based on color background

    Try this code. I have attached in your workbook also.

    ExtractColoredCells.xlsm

    Sub ExtractData()
        Dim lRed As Long
        Dim lYellow As Long
        Dim rng As Range
        Dim wksData As Worksheet
        Dim wksYellow As Worksheet
        Dim wksRed As Worksheet
        
        Set wksData = Sheets("Sheet1")
        Set wksYellow = Sheets("Sheet2")
        Set wksRed = Sheets("Sheet3")
        
        'Clear sheets
        wksYellow.Cells.Delete
        wksRed.Cells.Delete
    
        'Copy rows to correct sheet
        For Each rng In Range(wksData.Range("B3"), wksData.Range("B3").End(xlDown))
            Select Case rng.Interior.Color
            Case RGB(255, 255, 0)
                lYellow = lYellow + 1
                rng.EntireRow.Copy wksYellow.Cells(lYellow, 1)
            Case RGB(255, 0, 0)
                lRed = lRed + 1
                rng.EntireRow.Copy wksRed.Cells(lRed, 1)
            End Select
        Next rng
        wksYellow.Range("A1").CurrentRegion.Columns.AutoFit
        wksRed.Range("A1").CurrentRegion.Columns.AutoFit
    End Sub
    1. Reply to thread and inform if suggestion was helpful or not
    2. Click on the star (=Add Reputation) if you think someone helped you
    3. Mark [SOLVED] to this thread if solution was found. (On Menu "Thread Tools" > "Mark this thread as solved")

  4. #4
    Forum Contributor
    Join Date
    01-22-2013
    Location
    Pekanbaru, Indonesia
    MS-Off Ver
    Excel 2013 & Google Sheet
    Posts
    1,146

    Re: Macro extract data based on color background

    hi Nilem & Joakim N, you are really great...

    many thanks, i am helped...

+ 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. Macro to set value based on range of different cells with background color.
    By prem4u in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-28-2014, 12:55 PM
  2. [SOLVED] Macro to copy rows based on background color of cells within a range of columns
    By Chrispelletier in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-19-2013, 01:30 PM
  3. [SOLVED] Macro to change all cells with a certain background color in another background color
    By kevinvzandvoort in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-13-2012, 11:04 AM
  4. Macro Based on Cell Background Color
    By Kinchen in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-06-2011, 02:11 PM
  5. Change cell background color based on data?
    By proepert in forum Excel General
    Replies: 2
    Last Post: 11-18-2009, 01:02 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