Share via

VBA code help!

Anonymous
2022-08-15T20:28:12+00:00

Hi,

Hope sombody can help me with my code. Im new in this i believe this one is easy.

I get errors in the green lines. I am trying to select a range of a row with the variables created to do te loop. And then i want to copy that row and paste it in the next one.

But the sintaxis is rejected.

Thanks!!!

Sub Macro1()

For i = 2 To 140

f = i - 1

If Range("B" & i) = "" Then 

Rows(f).Select 

Range("B" & f:"J" & f).Select 

Application.CutCopyMode = False 

Selection.Copy 

Range("B" & i:"J" & i).Select 

ActiveSheet.Paste 

Rows(f).Select 

Range("M" & f:"O" & f).Select 

Application.CutCopyMode = False 

Selection.Copy 

Range("M" & i:"M" & i).Select 

ActiveSheet.Paste 

End If 

Next i

Microsoft 365 and Office | Excel | For education | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2022-08-15T21:32:06+00:00

Range("B" & f:"J" & f).Select

should be

Range("B" & f & ":J" & f).Select

It's similar for the others.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2022-08-15T23:12:51+00:00

    Worked perfectly. Thanks!

    Was this answer helpful?

    0 comments No comments