2

I Have the below Chunk of Excel VBA Code . Now I'll have to put them In a Loop & Parametrize them.

Countruz2 = 2
 Countruz3 = Countruz2 + 13

Range("A2:A15").PasteSpecial (xlPasteValues)

Below is what I've tried - 3 variants all failing with: Invalid use of Property Error.

'    Range ("A" & Countruz2 & ":" & "A" & Countruz3)                                    ' Invalid Use of Property

'    Range ("A" & Countruz2 & ":A" & Countruz3)                                         ' Invalid Use of Property

'    Range ("A" & Countruz2 & ":A" & Countruz2 + 13)                                    ' Invalid Use of Property

How do we deal with Such Concatenations & Parametrizations within the Range function in Excel VBA ?

Thanks for all the help in advance.

Edit :

Got it working after concatenating it like this -

X = "A" & Countruz2 & ":" & "A" & (Countruz2 + 13) Debug.Print X Range(X).PasteSpecial (xlPasteValues)

Any other elegant / simpler way?

1
  • 3
    You only need the top-left cell for the destination of a paste. Anything else is overkill and just another possible error when you get the destination size or orientation wrong. Commented Jul 10, 2018 at 19:12

1 Answer 1

1

Try this

Countruz2 = 2
Countruz3 = Countruz2 + 13

Range("A" & Countruz2 & ":A" & Countruz3).PasteSpecial (xlPasteValues)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.