0

I have a Range variable and a separate workbook which I try to fill with values. I use TheRange for it, first setting it to the range of clientsColl.Count rows and 1000 columns.

Dim TheRange As Range

With resultWorkbook.Worksheets("matrix_random")

    Set TheRange = _
        .Range(Cells(2, 2), Cells(clientsColl.Count, _
                                     1000)))

...
End With

However, I keep getting this error, can't figure out why..

Application-defined or object-defined error

7
  • 2
    you need the little . for the Cells, try .Range(.Cells(2, 2), .Cells(1000, clientsColl.Count))) , and you have the Rows and Columns switched in the second Cells Commented Nov 21, 2017 at 13:28
  • Where did you define clientsColl ? Commented Nov 21, 2017 at 13:28
  • @Shai Rado, Thank you, kind person! Saved me hours!! Commented Nov 21, 2017 at 13:30
  • 2
    @ShaiRado You have eagle's eyes. Good catch. :) Commented Nov 21, 2017 at 13:31
  • 2
    @sktneer LOL :) Commented Nov 21, 2017 at 13:33

1 Answer 1

3

Just for future users to get the an answer.

You need to qualify your .Cells with the With resultWorkbook.Worksheets("matrix_random") statement.

Also, the second Cells has Rows and Columns swapped.

Code

Dim TheRange As Range

With resultWorkbook.Worksheets("matrix_random")
    Set TheRange = .Range(.Cells(2, 2), .Cells(1000, clientsColl.Count)) '<-- you have 1 "extra" closing bracket
End With
Sign up to request clarification or add additional context in comments.

1 Comment

Good catch. plus 1

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.