Data Grab Macro

Chris86t

Board Regular
Joined
Feb 27, 2013
Messages
83
I have a excel sheet full of data. I need a macro that looks for where the RAG is Amber or Red and brings the information onto a separate tab.

The below table shows the source data this is on a tab called POAP DD-MM-YY (This date and tab will change every week)

CHANGE TYPEACTIVITY NAMEBUSINESS OWNERTRANSITION TEAM OWNERCRITICAL DEPENDENCIES/CONFLICTSSTART DATEPLANNED PROJECT HOURSEXPECTED COMPLETION DATEWEEKLY STATUS/UPDATE/ COMMENTSWEEKLY RAG
data1data1data1data1data1data1data1data1data1Amber
data2data2data2data2data2data2data2data2data2Green
data3data3data3data3data3data3data3data3data3Red

I then want the Macro to format the above data onto a new tab where the RAG says Amber or Red and looks like this
WEEKLY RAGACTIVITY NAMEBUSINESS OWNERTRANSITION TEAM OWNERWEEKLY STATUS/UPDATE/ COMMENTS
Amberdata1data1data1data1
Reddata3data3data3data3

Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Assuming your new tab is called "NewTab" and you already have the column headers in that tab, please see the following code. Make sure you run the macro when you are on the sheet that needs to be read.

VBA Code:
Sub Chris86t1()
Application.ScreenUpdating = False
Dim cl As Object, lastRow As Long, ws As Worksheet
Dim weeklyRag As String, activityName As String, businessOwner As String, teamOwner As String, weeklyStatus As String
Set ws = ActiveSheet
    For Each cl In ActiveSheet.Range("J:J")
        If cl.Value = "Amber" Or cl.Value = "Red" Then
            weeklyRag = cl.Value
            activityName = cl.Offset(0, -8).Value
            businessOwner = cl.Offset(0, -7).Value
            teamOwner = cl.Offset(0, -6).Value
            weeklyStatus = cl.Offset(0, -1).Value
            Sheets("NewTab").Activate
            lastRow = Cells(Rows.Count, 1).End(xlUp).Row
            Cells(lastRow, 1).Offset(1, 0).Select
            ActiveCell.Value = weeklyRag
            ActiveCell.Offset(0, 1).Value = activityName
            ActiveCell.Offset(0, 2).Value = businessOwner
            ActiveCell.Offset(0, 3).Value = teamOwner
            ActiveCell.Offset(0, 4).Value = weeklyStatus
            ws.Activate
        ElseIf cl.Value = "" Then
            Exit Sub
        End If
    Next cl
Application.ScreenUpdating = rue
End Sub
 
Upvote 0
Here another macro for you to consider.

Run the macro on your sheet with source data.
The macro assumes that the data starts in cell A2.

VBA Code:
Sub Macro1()
  Dim a As Variant, b As Variant, i As Long, j As Long
  a = Range("A2", Range("J" & Rows.Count).End(xlUp))
  ReDim b(1 To UBound(a, 1), 1 To 5)
  j = 1
  For i = 1 To UBound(a, 1)
    Select Case a(i, 10)
      Case "Amber", "Red"
        b(j, 1) = a(i, 10)
        b(j, 2) = a(i, 2)
        b(j, 3) = a(i, 3)
        b(j, 4) = a(i, 4)
        b(j, 5) = a(i, 9)
        j = j + 1
    End Select
  Next
  Sheets.Add after:=Sheets(ActiveSheet.Index)
  Range("A1").Resize(1, 5).Value = Array("WEEKLY RAG", "ACTIVITY NAME", "BUSINESS OWNER", "TRANSITION TEAM OWNER", "WEEKLY STATUS/UPDATE/ COMMENTS")
  Range("A2").Resize(UBound(b), 5).Value = b
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,524
Messages
6,120,049
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top