0

I want to use the Rowcount as the second Parameter for the Range.

Set R = Range("A1", Range("A" & Rows.Count).End(xlUp))

Range("N2":R).Value =...

How is it possible to use R here as the second Parameter?

Best regards!

3
  • 1
    Range("N2:N" & R).Value Commented May 9, 2018 at 9:23
  • 1
    @Zac I don't think the above will work, R is a range here. Perhaps this will Range("N2:N" & R.Rows.Count).Value =... Commented May 9, 2018 at 9:28
  • @JK2017: good shout.. I missed that R was set as range Commented May 9, 2018 at 9:33

3 Answers 3

1
Set R = Range("A1", Range("A" & Rows.Count).End(xlUp))
Range("N2:" & R.Address).Value =...
Sign up to request clarification or add additional context in comments.

Comments

0

Can look as a more complicated but is logical:

Set R = Range("a1", cells(rows.count, "A").end(xlup))
range("N2", cells(r.rows.count, "N")).value=...

Step-by-step solution:

Set lastA = cells(rows.count, "A").end(xlup)
set R = range("A1", lastA)

range("N2", cells(lastA.row, "N")).value = ...

Comments

0

pls try with below

Sub test()
    Dim r As Range
    Set r = Range("A1", Range("A" & Rows.Count).End(xlUp))
    Range("N2:N" & r.Rows.Count).Value = "R"
End Sub

4 Comments

Thanks for the answer, but I want to use "r" just for the second value of the Range, not for the whole
you want the second value of r range (i.e A2) in N2?
the solution above is perfectly working, thank you though!
@Marius, Good to hear. Thanks

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.