I have some code that will go through my sheet and find every cell in column A that has the value "Item". Then, it will copy the entire row directly beneath the cell that has the value "Item."
What I'd like to do is this:
- Go through the sheet and find each instance of "Invoice," "Invoice Date," and "City"
- When those cells are found, copy those cells and the cells immediately to their right
- Then go through and find every cell in column A that has the value "Item", and paste (with transpose) the two copied cells at the next blank column of that row.
- Then I'll copy the row beneath "Item" with the code I've already written below
Here is the code I have so far, along with a few pictures of what I'd like to do.
Please bear with me as I just started learning VBA yesterday and I'm very new. I know how to do some smaller parts of this, but the whole process is still hazy to me. Any advice appreciated. Thanks!
' Copy rows from one workbook to another at each instance of "Item"
Dim fromBook As Workbook
Dim toBook As Workbook
Application.ScreenUpdating = False
Set fromBook = Workbooks("from.xlsm")
Set toBook = Workbooks("to.xlsm")
Dim i As Range
For Each i In fromBook.Sheets("Sheet1").Range("A1:A1000")
Select Case i.Value
Case "Item"
toBook.Sheets("Sheet2").Range("A" & toBook.Sheets("Sheet2").Rows.Count).End(xlUp).Offset(1, 0).EntireRow.Value = i.Offset(1, 0).EntireRow.Value
Case Else
'do nothing
End Select
Next i
Application.ScreenUpdating = True
Before:
After:
Another After Option, if this is simpler: