Nadine Hernandez
Nadine Hernandez

Reputation: 1

Vba-excel - copying a range of cells in a loop

I am trying to find a cell and select it and the 13 rows below it so I can copy the selection go to the next column and paste it transposed.

My query is:

If cell.Value Like "*OR-*" Then
    Cells(ActiveCell, cell.Offset(0, 13)).Select
    cell.Copy 
    cell.Offset(0, 1)
    cell.Clear

I have no problem with copy and paste but it is selection what I want that is throwing me off

Upvotes: 0

Views: 55

Answers (1)

Shai Rado
Shai Rado

Reputation: 33692

First, copy 13 rows below is Cell.Offset(13,0) and not Cell.Offset(0, 13) (which is 13 column to the right).

Second, you don't need to Select the Range to copy it, just use the code below:

If Cell.Value Like "*OR-*" Then
    Range(Cell, Cell.Offset(13)).Copy
    Cell.Offset(, 1).PasteSpecial Paste:=xlPasteAll, Transpose:=True
    Cell.Clear
End If

Upvotes: 1

Related Questions