I am trying to copy and paste in two different workbooks, but the correct value is not being copied. I believe it is because I am using the "with" statement within another "with" statement, but I do not know how to avoid this since I am using a for loop. Here is my code so far:
Sub Approval_Flow()
Dim AppFlowWkb As Workbook, ConfigWkb As Workbook
Dim AppFlowWkst As Worksheet, ConfigWkst As Worksheet
Dim aCell As Range
Dim targetRng As Range
Set AppFlowWkb = Workbooks.Open("C:\Users\clara\Documents\Templates and Scripts\Flow Change.xlsx")
Set ConfigWkb = ThisWorkbook
Set AppFlowWkst = AppFlowWkb.Sheets("Editor")
Set ConfigWkst = ConfigWkb.Worksheets("Approval Flows")
With ConfigWkst
'looking through each column value before moving on to next row
For Each aCell In .Range("A1:K" & .UsedRange.Rows.Count)
'if cell is highlighted, copy that row's column D value
If Not aCell.Interior.Color = RGB(255, 255, 255) Then
Range("D" & (aCell.row)).Copy
'in appflow workbook, find empty row in column A and paste
With AppFlowWkst
Set targetRng = .Range("A" & Rows.Count).End(xlUp).Offset(1)
targetRng.PasteSpecial xlPasteValues
End With
'Range("C" & (aCell.row)).Copy
'With AppFlowWkst
'Set targetRng = .Range("B" & Rows.Count).End(xlUp).Offset(1)
'targetRng.PasteSpecial xlPasteValues
'once the rows' values have been pasted, move on to next row
End If
Next aCell
End With
End Sub
I hope the comments give you a good understanding as to what I am trying to do. Also, once I copy and paste all the values for that row, I would like the For Loop to continue not for that row, but for the next row. Any suggestions as to how I can make this happen? Thanks!