Macro to retrieve data with multiple criteria

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi All

I have the following macro but now I need to add in one more criteria that is when the cell in column D = "Unknown" and also the cell in column P = "Complete", please could anyone help to edit the macro. Many thanks.

VBA Code:
Dim c As Range, aryD As Variant, aryS As Variant, r As Long, sh1 As Worksheet, sh2 As Worksheet, i As Long

aryD = Array("A", "B", "C", "D", "E")
aryS = Array(1, 2, 3, 17, 15)
Set sh1 = Sheets("Previous Data")
Set sh2 = Sheets("RAG Status Unknown")
    With sh1
        r = 4
        For Each c In .Range("D2", .Cells(Rows.Count, 4).End(xlUp))
            If c = "Unknown" Then
                For i = LBound(aryS) To UBound(aryS)
                    sh2.Range(aryD(i) & r) = sh1.Cells(c.row, aryS(i)).Value
                Next
                r = r + 1
            End If
        Next
    End With
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try:
VBA Code:
If c = "Unknown" And .Cells(c.Row, "P") = "Complete" Then
 
Upvote 0
Solution
You're welcome, glad to help & thanks for the feedback. :)
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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