Hello everybody,
I am trying to write VBA code to copy cells from a range of non-contiguous columns (A:K, O:Q) to a new sheet if certain criteria is met (a cell in columns O:Q is populated and cells in column F do not contain a key word). I am able to specify the criteria but the code I've written to select the range of columns ('Select columns to copy) brings over all the original data. I'm unsure of how to still select the range "A:K,O:Q" and select the cell values that match the criteria.
Any guidance would be much appreciated.
I am trying to write VBA code to copy cells from a range of non-contiguous columns (A:K, O:Q) to a new sheet if certain criteria is met (a cell in columns O:Q is populated and cells in column F do not contain a key word). I am able to specify the criteria but the code I've written to select the range of columns ('Select columns to copy) brings over all the original data. I'm unsure of how to still select the range "A:K,O:Q" and select the cell values that match the criteria.
Code:
Sub CopyValues()
Set i = Sheets("Sheet1")
Set e = Sheets("Sheet2")
Dim d
Dim j
d = 1
j = 2
'Choose length of data to copy
Do Until IsEmpty(i.Range("A" & j))
'Specify criteria
If (i.Range("O" & j) <> "" Or i.Range("P" & j) <> "" Or i.Range("Q" & j) <> "") And _
i.Range("F" & j) <> "HR" Then
d = d + 1
'Select columns to copy
i.Range("A:K,O:Q").Copy e.Range("A1")
End If
j = j + 1
Loop
End Sub
Any guidance would be much appreciated.