+ Reply to Thread
Results 1 to 4 of 4

Macro to extract Rows Colored with Yellow Fill and create a new sheet as per current month

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-03-2004
    Location
    India
    MS-Off Ver
    2013
    Posts
    205

    Macro to extract Rows Colored with Yellow Fill and create a new sheet as per current month

    Hello All,

    I am using Excel 2010 and have the following problem.

    I have a macro which looks up Value in Col C and compare it with Col B and color the value with yellow background color (See Account Sheet sample attached)

    I want a macro which should copy all the yellow colored Cells from Account sheet together with Col A C D F H I K showing only the current month Column shown in Row 1.
    Eg if the macro is run in the month of Aug the macro should create a new sheet named Aug

    In September the new sheet would be Sept and so on and so forth

    See the result on sheet for Aug required

    A new macro or a modified version of my macro would help

    Thanks in advance
    Rashid Khan
    Attached Files Attached Files
    Last edited by prkhan56; 08-09-2016 at 10:24 PM.

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to extract Rows Colored with Yellow Fill and create a new sheet as per current m

    Try:
    Sub foo()
        Dim wsSrc As Worksheet
        Dim wsTgt As Worksheet
        Dim arrCopy() As Variant
        Dim i As Integer
        Dim iMonth As String
        Dim sMonth As String
        
        On Error GoTo Terminate
        With Application
            .ScreenUpdating = False
            .DisplayAlerts = False
        End With
            
        Set wsSrc = Worksheets("Account")
        arrCopy = Array("A", "B", "D", "F", "H", "I", "K")
        
        iMonth = Month(Date)
        sMonth = Format(Date, "MMM")
        
        If SheetExists(sMonth) Then Worksheets(sMonth).Delete
        Set wsTgt = Worksheets.Add(After:=Worksheets(Worksheets.Count))
        wsTgt.Name = sMonth
        
        With wsSrc
            .AutoFilterMode = False
            .UsedRange.AutoFilter field:=2, Criteria1:=RGB(255, 255, 0), Operator:=xlFilterCellColor
            For i = LBound(arrCopy) To UBound(arrCopy)
                .UsedRange.Columns(arrCopy(i)).SpecialCells(xlCellTypeVisible).Copy wsTgt.Cells(1, i + 1)
            Next i
            .UsedRange.Columns(11 + iMonth).SpecialCells(xlCellTypeVisible).Copy wsTgt.Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)
            .AutoFilterMode = False
        End With
        
    Terminate:
        If Err Then
            Debug.Print "ERROR", Err.Number, Err.Description
            Err.Clear
        End If
        With Application
            .DisplayAlerts = True
            .ScreenUpdating = True
        End With
    End Sub
    
    Function SheetExists(ByVal sSheetName As String) As Boolean
        Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
            If UCase(ws.Name) = UCase(sSheetName) Then
                SheetExists = True
                Exit Function
            End If
        Next ws
    End Function
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    06-03-2004
    Location
    India
    MS-Off Ver
    2013
    Posts
    205

    Re: Macro to extract Rows Colored with Yellow Fill and create a new sheet as per current m

    Hello Olly,
    Super code...works like a charm.
    Thanks a million for your help

    Thread marked SOLVED

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to extract Rows Colored with Yellow Fill and create a new sheet as per current m

    Happy to help. Don't forget to click 'Add Reputation' as well!

+ 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. Replies: 1
    Last Post: 01-05-2016, 03:03 AM
  2. [SOLVED] Macro to cut and paste current month sheet into the relevant month chosen by a drop down
    By scotty22 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-06-2015, 09:07 AM
  3. Macro to create graph up to current month
    By danfullwood in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-30-2014, 04:12 AM
  4. Help to create Macro to Auto-fill end of month based on given start and end dates
    By patidallas22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2014, 11:26 AM
  5. Create Macro to move values from the current sheet in which the macro is activated
    By Turkish1801 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2013, 06:11 PM
  6. Macro to duplicate current sheet and incrementally rename by month
    By jerrydiaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-05-2013, 12:31 PM
  7. [SOLVED] only cells that are colored yellow
    By childothe1980s in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2006, 01:00 PM

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