Macro to retrieve data with multiple criteria

Apple08

Active Member
Joined
Nov 1, 2014
Messages
404
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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,963
Office Version
  1. 365
Platform
  1. Windows
Try:
VBA Code:
If c = "Unknown" And .Cells(c.Row, "P") = "Complete" Then
 
Solution

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,963
Office Version
  1. 365
Platform
  1. Windows
You're welcome, glad to help & thanks for the feedback. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,130,072
Messages
5,639,906
Members
417,118
Latest member
warranty123

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
Top