I want to create a macro that copies a row-range if the cell in column DA contains a specific value.
For example:
If the column DA10 contains the value 3-incompletion, N10 contaings nothing, CI10 contains nothing - then the macro should copy the cells F10, H10 and DA10 into the workbook reportWB. I don't know how to do it.
Progression so far (thanks to Shai - I'm still to stupid to make it work):
Sub insertINCOMPLETION()
Dim dataWB As Workbook
Dim reportWB As Workbook
Dim workB As Workbook
Dim incomplRNG As Range
Dim LastRow6 As Long
Dim LastRow7 As Long
For Each workB In Application.Workbooks
If Left(workB.Name, 5) = "15B2" Then
Set dataWB = workB
Exit For
End If
Next
If Not dataWB Is Nothing Then
Set reportWB = ThisWorkbook
With reportWB.Sheets("getDATA")
LastRow6 = .Cells(.Rows.Count, "B").End(xlUp).Offset(1).Row
End With
With dataWB.Sheets("Data")
LastRow7 = .Cells(.Rows.Count, "F").End(xlUp).Row
If InStr(.Range("DA" & LastRow7).Value2, "3-Incompletion") > 0 And _
Trim(.Range("N" & LastRow7).Value2) = "" And _
Trim(.Range("CI" & LastRow7).Value2) = "" Then
Set incomplRNG = Application.Union(.Range("F8:F" & LastRow7), .Range("H8:H" & LastRow7), .Range("DA8:DA" & LastRow7))
incomplRNG.Copy
reportWB.Sheets("getDATA").Range("B" & LastRow6).PasteSpecial xlPasteValues
End If
End With
End If
End Sub
Still doesn't work. Ends after checking the column DA.
"3-incompletion"
? You can useIf InStr(.Cells(10, "AD"), "3-incompletion") > 0 Then
– Shai Rado