1

I've the following code extract below,

Dim profileRange as Variant

profileRange = ActiveWorkbook.Worksheets("Scenario").Range(Cells(1, "C"), Cells(5, "C"))

Then I get the following in the watch expression

Watch Expression: profileRange
Value: Empty
Type: Variant/Empty

It's supposed to get the numbers assigned in that sheet..which goes form 1 to 5

Also, I get this when running the code

Error 1004:
Application or Object defined error

Can someone please help?

1 Answer 1

1

Change:

profileRange = ActiveWorkbook.Worksheets("Scenario").Range(Cells(1, "C"), Cells(5, "C"))

to this:

With ActiveWorkbook.Worksheets("Scenario")
    profileRange = .Range(.Cells(1, "C"), .Cells(5, "C"))
End with

Cells() are range object and need to have parentage assigned. Without dictating parentage it is trying to use the active sheet, so the range parentage does not equate to the cells parentage.

By using the With block with the . allows consistent parentage throughout.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey Scott, how do I assign this to the profileRange?
@lukieleetronic sorry forgot the array. I fixed it. Please consider marking as correct.

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.